当前位置:编程学习 > C#/ASP.NET >>

Wince FTP WinAPI 大放送

最近很多网络的朋友找我,咨询wince下实现FTP的功能;
那也是我5年前刚接触wince的时候碰见的问题,也是经过一个朋友的指点得以解决。
由于时间很久了,加上最近本人非常的忙,所以没有时间来得及回复。
昨晚我抽空翻阅了下以前的文档,现在我将源代码贴出来,
希望后面的朋友能够顺利解决问题,早日脱离这个苦海(,顺利跳入下个苦海)
Wince  FTP  WinAPI --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SimpleFtp
{
    internal class WinAPI
    {
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public class WIN32_FIND_DATA
        {
            public UInt32 dwFileAttributes = 0;
            public FILETIME ftCreationTime;
            public FILETIME ftLastAccessTime;
            public FILETIME ftLastWriteTime;
            public UInt32 nFileSizeHigh = 0;
            public UInt32 nFileSizeLow = 0;
            public UInt32 dwReserved0 = 0;
            public UInt32 dwReserved1 = 0;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
            public string cFileName = null;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
            public string cAlternateFileName = null;
        };
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public class FILETIME
        {
            public int dwLowDateTime = 0;
            public int dwHighDateTime = 0;
        };

        public const int INTERNET_FLAG_PASSIVE = 0x8000000; //被动模式
        public const int INTERNET_FLAG_PORT = 0x0;          //主动模式

        public const uint INTERNET_FLAG_RELOAD = 0x80000000;         //
        public const uint INTERNET_FLAG_KEEP_CONNECTION = 0x400000;  //
        public const uint INTERNET_FLAG_MULTIPART = 0x200000;        //

        public const int INTERNET_OPEN_TYPE_PRECONFIG = 0;
        public const int INTERNET_OPEN_TYPE_DIRECT = 1;
        public const int INTERNET_OPEN_TYPE_PROXY = 3;

        public const int INTERNET_SERVICE_FTP = 1;
        public const int INTERNET_SERVICE_GOPHER = 2;
        public const int INTERNET_SERVICE_HTTP = 3;

        public const uint FTP_TRANSFER_TYPE_ASCII = 0x1;
        public const uint FTP_TRANSFER_TYPE_BINARY = 0x2;

        public const int FILE_ATTRIBUTE_READONLY = 0x1;
        public const int FILE_ATTRIBUTE_HIDDEN = 0x2;
        public const int FILE_ATTRIBUTE_SYSTEM = 0x4;
        public const int FILE_ATTRIBUTE_DIRECTORY = 0x10;
        public const int FILE_ATTRIBUTE_ARCHIVE = 0x20;
        public const int FILE_ATTRIBUTE_NORMAL = 0x80;
        public const int FILE_ATTRIBUTE_TEMPORARY = 0x100;
        public const int FILE_ATTRIBUTE_COMPRESSED = 0x800;
        // 连接和初始化
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern void SetLastError(int dwErrCode);

        // 连接和初始化
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr InternetOpen(string strAppName, int nAccessType, string strProxy, string strProxyBypass, int nFlags);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr InternetConnect(IntPtr hInet, string strServer, int nPort, string strUser, string strPassword
            , int nService, int nFlags, int nContext);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetCloseHandle(IntPtr hSession);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetGetConnectedState(ref int ulFlags, int ulReserved);

        // Ftp文件操作命令
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr FtpFindFirstFile(IntPtr hSession, string strPath, [In, Out] WIN32_FIND_DATA dirData, int nFlags, int nContext);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetFindNextFile(IntPtr hFind, [In, Out] WIN32_FIND_DATA dirData);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpGetFile(IntPtr hFtpSession, string lpszRemoteFile, string lpszNewFile
            , bool fFailIfExists, int dwFlagsAndAttributes, uint dwFlags, int dwContext);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpPutFile(IntPtr hFtpSession, string lpszLocalFile, string lpszRemoteFile
            , uint dwFlags, int dwContext);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpDeleteFile(IntPtr hFtpSession, string lpszFileName);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpRenameFile(IntPtr hFtpSession, string lpszExisting, string lpszNew);

        // Ftp目录操作命令
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpGetCurrentDirectory(IntPtr hFtpSession, [In, Out] string lpszCurrentDirectory, ref int lpdwCurrentDirectory);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpSetCurrentDirectory(IntPtr hFtpSession, string lpszCurrentDirectory);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpCreateDirectory(IntPtr hFtpSession, string lpszDirectory);

        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool FtpRemoveDirectory(IntPtr hFtpSession, string lpszDirectory);

    }
}

--------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace SimpleFtp
{
    internal class FtpAccess
    {
        private string m_szIP = null;
        private int m_nPort = -1;
        private string m_szUserName = null;
        private string m_szPassword = null;

        private IntPtr m_hInternet = IntPtr.Zero;
        private IntPtr m_hConnect = IntPtr.Zero;

        /// <summary>
        /// 获取或设置FTP的访问IP地址
        /// </summary>
        public string IP
        {
            get
            {
                return this.m_szIP;
            }
            set
            {
                this.m_szIP = value;
            }
        }
        /// <summary>
        /// 获取或设置FTP的访问端口号
        /// </summary>
        public int Port
        {
            get
            {
                return this.m_nPort;
            }
            set
            {
                this.m_nPort = value;
            }
        }
        /// <summary>
        /// 获取或设置FTP的访问用户名称
        /// </summary>
        public string UserName
        {
            get
            {
                return this.m_szUserName;
            }
            set
            {
                this.m_szUserName = value;
            }
        }
        /// <summary>
        /// 获取或设置FTP的访问用户密码
        /// </summary>
        public string Password
        {
            get
            {
                return this.m_szPassword;
            }
            set
            {
                this.m_szPassword = value;
            }
        }

        /// <summary>
        /// 连接到FTP指定的路径
        /// </summary>
        /// <param name="path">路径</param>
        public bool Connect()
        {
            this.InitWinAPI();
            if (this.m_hConnect != IntPtr.Zero)
            {
                if (WinAPI.FtpSetCurrentDirectory(this.m_hConnect, "/"))
                    return true;
            }
            this.CloseConnection();

            if (this.m_szIP == null || this.m_szUserName == null || this.m_szPassword == null)
            {
                //CommonDef.SetLastError("FTP站点连接失败!FTP访问参数未设置");
                return false;
            }

            this.m_hInternet = WinAPI.InternetOpen("ftp", WinAPI.INTERNET_OPEN_TYPE_PRECONFIG, null, null, 0);
            if (this.m_hInternet == null || this.m_hInternet == IntPtr.Zero)
            {
                //CommonDef.SetLastError("FTP站点连接失败!" + this.GetWin32Error());
                return false;
            }

            this.m_hConnect = WinAPI.InternetConnect(this.m_hInternet, this.IP, this.Port, this.UserName, this.Password
                , WinAPI.INTERNET_SERVICE_FTP, WinAPI.INTERNET_FLAG_PASSIVE, 0);
            if (this.m_hConnect == null || this.m_hConnect == IntPtr.Zero)
            {
                //CommonDef.SetLastError("FTP站点连接失败!" + this.GetWin32Error());
                return false;
            }

            if (!WinAPI.FtpSetCurrentDirectory(this.m_hConnect, "/"))
            {
                //CommonDef.SetLastError("FTP站点连接失败!" + this.GetWin32Error());
                return false;
            }
            return true;
        }
        /// <summary>
        /// 关闭FTP连接
        /// </summary>
        public void CloseConnection()
        {
            if (this.m_hConnect != IntPtr.Zero)
            {
                WinAPI.InternetCloseHandle(this.m_hConnect);
                this.m_hConnect = IntPtr.Zero;
            }
            if (this.m_hInternet != IntPtr.Zero)
            {
                WinAPI.InternetCloseHandle(this.m_hInternet);
                this.m_hInternet = IntPtr.Zero;
            }
        }
        /// <summary>
        /// 判断文件或文件夹是否存在
        /// </summary>
        /// <param name="path">文件或文件夹路径</param>
        /// <param name="bIsFolder">资源是否是文件夹</param>
        /// <returns>true:资源存在;false:资源不存在</returns>
        public bool ResExists(string szResPath, bool bIsFolder)
        {
            szResPath = szResPath.Trim();
            if (szResPath == "/" || szResPath == "")
                return true;

            if (!this.Connect())
                return false;

            this.InitWinAPI();
            //if (bIsFolder)
            //{
            if (!WinAPI.FtpSetCurrentDirectory(this.m_hConnect, szResPath))
            {
                return false;
            }
            if (!WinAPI.FtpSetCurrentDirectory(this.m_hConnect, "/"))
            {
                return false;
            }
            return true;
            //}
            //else
            //{
            //    WinAPI.WIN32_FIND_DATA stFileInfo = new WinAPI.WIN32_FIND_DATA();
            //    IntPtr hFile = WinAPI.FtpFindFirstFile(this.m_hConnect, szResPath, stFileInfo, 0, 0);
            //    if (hFile == null || hFile == IntPtr.Zero)
            //    {
            //        return false;
            //    }
            //    WinAPI.InternetCloseHandle(hFile);
            //    return true;
            //}
        }

        /// <summary>
        /// 删除一个本地文件
        /// </summary>
        /// <param name="szFileName">本地文件</param>
        /// <param name="bRaiseException">是否抛出异常</param>
        /// <returns>bool</returns>
        private bool DeleteFile(string szFileName, bool bRaiseException)
        {
            if (!File.Exists(szFileName))
                return true;
            try
            {
                File.Delete(szFileName);
                return true;
            }
            catch (Exception ex)
            {
                if (bRaiseException)
                    throw ex;
                return false;
            }
        }

        private bool RenameFile(string szFileName, string szNewName, bool bRaiseException)
        {
            if (!File.Exists(szFileName))
                return true;
            try
            {
                File.Move(szFileName, szNewName);
                return true;
            }
            catch (Exception ex)
            {
                if (bRaiseException)
                    throw ex;
                return false;
            }
        }

        /// <summary>
        /// 上传本地文件到服务器
        /// </summary>
        /// <param name="szLocalFile">本地源文件全路径</param>
        /// <param name="szRemoteFile">目的服务器文件全路径</param>
        /// <returns>true:上传成功;false:上传失败</returns>
        public bool Upload(string szLocalFile, string szRemoteFile)
        {
            FileInfo fileInfo = new FileInfo(szLocalFile);
            if (fileInfo == null || !fileInfo.Exists)
                return false;

            if (!File.Exists(szLocalFile))
            {
                //CommonDef.SetLastError(string.Format("文件{0}上传失败!本地文件不存在!", szLocalFile));
                return false;
            }

            //if (this.ResExists(szRemoteFile, false))
            //{
            //    string szErrorInfo = string.Format("文件{0}上传到{1}失败!远程文件已经存在!"
            //        , szLocalFile, szRemoteFile);
            //CommonDef.SetLastError(szErrorInfo);
            //    return false;
            //}

            this.InitWinAPI();
            if (!WinAPI.FtpPutFile(this.m_hConnect, szLocalFile, szRemoteFile, WinAPI.FTP_TRANSFER_TYPE_BINARY | WinAPI.INTERNET_FLAG_RELOAD, 0))
            {
                string szErrorInfo = string.Format("文件{0}上传到文件{1}失败!", szLocalFile, szRemoteFile);
                //CommonDef.SetLastError(szErrorInfo + this.GetWin32Error());
                return false;
            }
            return true;
        }
        /// <summary>
        /// 下载指定的FTP路径上的文件
        /// </summary>
        /// <param name="szRemoteFile">远程文件</param>
        /// <param name="szLocalFile">保存本地文件名</param>
        /// <returns>true:下载成功;false:下载失败</returns>
        public bool Download(string szRemoteFile, string szLocalFile)
        {
            try
            {
                this.RenameFile(szLocalFile, szLocalFile + ".tmp", true);
            }
            catch (Exception ex)
            {
                string szErrorInfo = string.Format("文件{0}下载到文件{1}失败!无法重命名本地已存在文件"
                    , szRemoteFile, szLocalFile);
                //CommonDef.SetLastError(szErrorInfo + ex.Message);
                return false;
            }

            //if (!this.ResExists(szRemoteFile, false))
            //{
            //CommonDef.SetLastError(string.Format("文件{0}下载失败!远程文件不存在!", szRemoteFile));
            //    return false;
            //}

            this.InitWinAPI();
            //INTERNET_FLAG_RELOAD..清空缓存...
            if (!WinAPI.FtpGetFile(this.m_hConnect, szRemoteFile, szLocalFile, false, 0, WinAPI.FTP_TRANSFER_TYPE_BINARY | WinAPI.INTERNET_FLAG_RELOAD, 0))
            {
                //更改文件名,否则FtpGetFile函数会自动删除本地的文件...
                this.RenameFile(szLocalFile + ".tmp", szLocalFile, false);
                string szError = this.GetWin32Error();
                string szErrorInfo = string.Format("文件{0}下载到文件{1}失败!", szRemoteFile, szLocalFile);
                //CommonDef.SetLastError(szErrorInfo + this.GetWin32Error());
                return false;
            }
            if (!File.Exists(szLocalFile))
            {
                //更改文件名,否则FtpGetFile函数会自动删除本地的文件...
                this.RenameFile(szLocalFile + ".tmp", szLocalFile, false);
                string szErrorInfo = string.Format("文件{0}下载到文件{1}失败!", szRemoteFile, szLocalFile);
                //CommonDef.SetLastError(szErrorInfo);
                return false;
            }
            //删除本地的临时文件...
            this.DeleteFile(szLocalFile + ".tmp", false);
            return true;
        }
--------------------编程问答--------------------

   /// <summary>
        /// 创建指定路径上所有缺失的目录
        /// </summary>
        /// <param name="dirPath">目录</param>
        /// <returns>bool</returns>
        public bool CreateDirectory(string szDirPath)
        {
            if (this.ResExists(szDirPath, true))
                return true;

            string[] arrDirName = szDirPath.Split(new char[] { '/' });
            szDirPath = string.Empty;
            for (int index = 0; index < arrDirName.Length; index++)
            {
                string szDirName = arrDirName[index];
                if (szDirName == null || szDirName.Trim() == string.Empty)
                    continue;
                szDirPath += "/" + szDirName;
                if (this.ResExists(szDirPath, true))
                    continue;
                this.InitWinAPI();

                if (!WinAPI.FtpCreateDirectory(this.m_hConnect, szDirPath))
                {
                    string szErrorInfo = string.Format("目录{0}创建失败!", szDirPath);
                    //CommonDef.SetLastError(szErrorInfo + this.GetWin32Error());
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// 获取指定目录的文件列表
        /// </summary>
        /// <param name="szDirPath">目录路径</param>
        /// <param name="bFolder">是否为文件夹属性</param>
        /// <param name="lstFilePath">返回的文件列表</param>
        /// <returns>bool</returns>
        public bool GetFileList(string szDirPath, bool bFolder, ref List<string> lstFilePath)
        {
            if (!this.ResExists(szDirPath, true))
            {
                string szErrorInfo = string.Format("列表目录{0}下的文件失败!远程目录不存在", szDirPath);
                //CommonDef.SetLastError(szErrorInfo + this.GetWin32Error());
                return false;
            }
            WinAPI.WIN32_FIND_DATA stFileInfo = new WinAPI.WIN32_FIND_DATA();
            IntPtr hFile = WinAPI.FtpFindFirstFile(this.m_hConnect, szDirPath, stFileInfo, 0, 0);
            if (hFile == IntPtr.Zero)
                return false;

            if (lstFilePath == null)
                lstFilePath = new List<string>();

            // 遍历父目录查找指定的子目录是否存在
            bool bSuccess = true;
            while (bSuccess)
            {
                if (bFolder)
                {
                    if (this.IsDirectory(stFileInfo.dwFileAttributes))
                    {
                        string szChildPath = string.Format("{0}/{1}", szDirPath, stFileInfo.cFileName);
                        lstFilePath.Add(szChildPath);
                    }
                }
                else
                {
                    if (!this.IsDirectory(stFileInfo.dwFileAttributes))
                    {
                        string szChildPath = string.Format("{0}/{1}", szDirPath, stFileInfo.cFileName);
                        lstFilePath.Add(szChildPath);
                    }
                }
                bSuccess = WinAPI.InternetFindNextFile(hFile, stFileInfo);
            }
            WinAPI.InternetCloseHandle(hFile);
            return true;
        }
        /// <summary>
        /// 指定的文件属性是否是文件夹属性
        /// </summary>
        /// <param name="dwFileAttributes">文件属性</param>
        /// <returns>bool</returns>
        private bool IsDirectory(UInt32 dwFileAttributes)
        {
            if ((dwFileAttributes & WinAPI.FILE_ATTRIBUTE_DIRECTORY) == WinAPI.FILE_ATTRIBUTE_DIRECTORY)
                return true;
            else
                return false;
        }

        private void InitWinAPI()
        {
            //CommonDef.SetLastError(null);
            //WinAPI.SetLastError(0);
        }

        private string GetWin32Error()
        {
            //int nErrorCode = Marshal.GetLastWin32Error();
            //if (nErrorCode == 0)
            //    return null;
            //return (new Win32Exception(nErrorCode)).Message;
            return string.Empty;
        }
    }
}

--------------------编程问答-------------------- 沙画 --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace SimpleFtp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btConnect_Click(object sender, EventArgs e)
        {
            FtpAccess ftpp = new FtpAccess();
            ftpp.IP = "192.168.123.161";
            ftpp.Port = 21;
            ftpp.UserName = "zhou";
            ftpp.Password = "";

            if (ftpp.Connect())
            {
                try
                {
                    if (ftpp.Upload("\\DiskOnChip\\asd.jpg", "\\asd.jpg"))
                    {
                        MessageBox.Show("上传成功...");
                        ftpp.CloseConnection();
                        
                    }
                    else
                    {
                        MessageBox.Show("下载文件失败...");
                        ftpp.CloseConnection();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("下载文件失败..."+ex.ToString());
                    ftpp.CloseConnection();
                    return ;
                }
            }
            else
            {
                MessageBox.Show("FTP连接失败...");
            }
            ftpp.CloseConnection();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            FtpAccess ftpp = new FtpAccess();
            ftpp.IP = "192.168.123.161";
            ftpp.Port = 21;
            ftpp.UserName = "zhou";
            ftpp.Password = "";
           
              //bool ConnectStates =ftpp.Connect() ;
            if (ftpp.Connect())
            //if(ConnectStates ==true)
            {
                try
                {
                    if (ftpp.Download("\\EmployeeTxt.txt", "\\DiskOnChip\\EmployeeTxt.txt"))
                    {
                        MessageBox.Show("下载文件成功...");
                        ftpp.CloseConnection();
                    }
                    else
                    {
                        MessageBox.Show("下载文件失败...");
                        ftpp.CloseConnection();
                        return;
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show("下载文件失败..."+ex.ToString());
                    ftpp.CloseConnection();
                    return;
                }
            }
            else
            {
                MessageBox.Show("FTP连接失败...");
            }
            //ftpp.CloseConnection();
        }
    }
}

--------------------编程问答--------------------

完毕
--------------------编程问答-------------------- 帮顶 --------------------编程问答-------------------- 顶啊顶 --------------------编程问答--------------------  mark --------------------编程问答-------------------- 药师v587 --------------------编程问答--------------------
引用 8 楼 zhengfujie 的回复:
顶啊顶



--------------------编程问答-------------------- --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 那就 谢谢分享喽 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 楼主太有爱了,感谢分享 --------------------编程问答-------------------- 顶   --------------------编程问答-------------------- win7 + winc5.0 测试成功 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 脚印留下,可能近期就要用到,感谢 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 药师v587  --------------------编程问答-------------------- 感谢楼主分享 --------------------编程问答-------------------- 老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009 --------------------编程问答-------------------- 楼主真好!受教了! --------------------编程问答-------------------- 谢谢楼主哈 --------------------编程问答--------------------
引用 34 楼 oushengfen 的回复:
老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了 --------------------编程问答-------------------- 谢谢楼主哈 --------------------编程问答-------------------- 感谢楼主分享,支持提供源码的所有朋友~ --------------------编程问答-------------------- 哇~~正想要这个啊~~~一上来就看到~ --------------------编程问答-------------------- 这个可以有 --------------------编程问答-------------------- 尽管现在不用,收藏再说!!! --------------------编程问答-------------------- MARK 好东西 谢谢楼主 支持 --------------------编程问答-------------------- 尽管现在不用,收藏再说!!!  --------------------编程问答--------------------

尽管现在不用,收藏再说!!!  --------------------编程问答-------------------- 路过帮顶。。。 --------------------编程问答-------------------- 收藏 --------------------编程问答-------------------- 不错。。。。。。。。。。。。。 --------------------编程问答-------------------- mark --------------------编程问答-------------------- --------------------编程问答-------------------- mark一下,备用 --------------------编程问答-------------------- 谢谢你的分享 --------------------编程问答-------------------- 感谢LZ分享~~ --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 以前尝试过一些开源的,不好用,放弃FTP了,改用HTTP,这个有机会再试。 --------------------编程问答-------------------- 好东西 --------------------编程问答--------------------   --------------------编程问答-------------------- 跪求大神
http://bbs.csdn.net/topics/390466572?page=1#post-394558774 --------------------编程问答--------------------  好东西 顶一哈 --------------------编程问答--------------------
引用 37 楼 zhouzhangkui 的回复:
Quote: 引用 34 楼 oushengfen 的回复:

老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了

简直是笑话,还使用无数次了,在PC上使用无数次吧,WINCE上跟本不存在"kernel32.dll",WinCE上用的是coredll.dll --------------------编程问答-------------------- 收藏。。。。。。。。。。。。 --------------------编程问答-------------------- mark   --------------------编程问答-------------------- 顶!mark!! --------------------编程问答-------------------- 你5年前遇到的?这段代码,我在6年多前在一外国开源网站上搜到的。 --------------------编程问答-------------------- 而且,这代码走的是TCP协议。 --------------------编程问答-------------------- --------------------编程问答-------------------- 上传下载文件地址总报错 --------------------编程问答-------------------- 楼主有爱啊~~~ --------------------编程问答-------------------- 顶下,感谢分享!!! --------------------编程问答-------------------- FtpPutFile有时会让Wince网络系统死掉,就是无法再使用网络功能,除非重起设备,不知怎么回事。 --------------------编程问答-------------------- 感谢分享。。。 --------------------编程问答-------------------- 学习了不错 的 --------------------编程问答-------------------- mark吧,万一有用了 --------------------编程问答-------------------- 这个不错。以后看能不能用得着。 --------------------编程问答-------------------- 留名,暂时用不到,或许以后有用 --------------------编程问答-------------------- --------------------编程问答-------------------- 非常好》。。 --------------------编程问答--------------------
引用 62 楼 llxxhm 的回复:
Quote: 引用 37 楼 zhouzhangkui 的回复:

Quote: 引用 34 楼 oushengfen 的回复:

老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了

简直是笑话,还使用无数次了,在PC上使用无数次吧,WINCE上跟本不存在"kernel32.dll",WinCE上用的是coredll.dll


这段代码,我使用过,不少朋友之前通过qq问我要,他们拿到之后也都用的好好的
不试就没有发言权!
实践是检验整理的唯一标准! --------------------编程问答--------------------
引用 62 楼 llxxhm 的回复:
Quote: 引用 37 楼 zhouzhangkui 的回复:

Quote: 引用 34 楼 oushengfen 的回复:

老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了

简直是笑话,还使用无数次了,在PC上使用无数次吧,WINCE上跟本不存在"kernel32.dll",WinCE上用的是coredll.dll

请问你 认真看程序了吗?
程序里调用了 SetLastError(int dwErrCode) 这个函数吗?
请你还是认真的看懂别人的程序,真正拿去自己调试过,再评价吧 --------------------编程问答--------------------
引用 62 楼 llxxhm 的回复:
Quote: 引用 37 楼 zhouzhangkui 的回复:

Quote: 引用 34 楼 oushengfen 的回复:

老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了

简直是笑话,还使用无数次了,在PC上使用无数次吧,WINCE上跟本不存在"kernel32.dll",WinCE上用的是coredll.dll



这位老兄,不知道你有没有看一下问题是否出在其他地方,楼主提供的代码我在wince5.0+.netframework3.5下调试通过,能够正常使用的,没有出现什么问题,代码直接拿过来,自己配置了ftp的账号密码就可以。

如果不确定问题所在的话,请不要随便指责。 --------------------编程问答-------------------- 支持提供代码的朋友。

如果自己没有完整测试,没有发言权。 --------------------编程问答-------------------- 尽管现在不用,收藏再说!!!  --------------------编程问答--------------------
引用 82 楼 john_huang 的回复:
Quote: 引用 62 楼 llxxhm 的回复:

Quote: 引用 37 楼 zhouzhangkui 的回复:

Quote: 引用 34 楼 oushengfen 的回复:

老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了

简直是笑话,还使用无数次了,在PC上使用无数次吧,WINCE上跟本不存在"kernel32.dll",WinCE上用的是coredll.dll



这位老兄,不知道你有没有看一下问题是否出在其他地方,楼主提供的代码我在wince5.0+.netframework3.5下调试通过,能够正常使用的,没有出现什么问题,代码直接拿过来,自己配置了ftp的账号密码就可以。

如果不确定问题所在的话,请不要随便指责。


引用 81 楼 zhouzhangkui 的回复:
Quote: 引用 62 楼 llxxhm 的回复:

Quote: 引用 37 楼 zhouzhangkui 的回复:

Quote: 引用 34 楼 oushengfen 的回复:

老大,你上述代码是否在WINCE下,真正使用过?
1、kernel32.dll WINCE平台的是coredll;
2、FtpPutFile在WINCE下是不能使用的。是需要使用FtpOpenFile,InternetWriteFile进行上传。

http://blog.csdn.net/oushengfen/article/details/8863009


已经使用过无数次了

简直是笑话,还使用无数次了,在PC上使用无数次吧,WINCE上跟本不存在"kernel32.dll",WinCE上用的是coredll.dll

请问你 认真看程序了吗?
程序里调用了 SetLastError(int dwErrCode) 这个函数吗?
请你还是认真的看懂别人的程序,真正拿去自己调试过,再评价吧

不好意思,确实没认真看,本人没用过C#,一直用C++的,所以也没试,只是粗看了一下觉得CE下没有kernel32.dll所以武断了,非常抱歉!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,