由于项目需要开发了一套,远程服务器ftp下载文件的工具,由于各个服务器使用的ftp服务器不同,c#自带的ftp类是无法使用的,所以使用ftp.exe这个工具来进行ftp的上传与下载,这部分看似简单,但是使用常见的方法却难以实现,原因就是自动命令行输入用户名与密码的问题。
方法一:FtpWebRequest+FtpWebResponse
这种方式就是利用自带的类进行ftp上传下载,经过尝试有些可用有些不可用,具体用法可百度信息很多。
方法二:使用Process调用ftp.exe 此方法不可用,原因为填写ftp密码时无法自动写入。
string filepath = System.AppDomain.CurrentDomain.BaseDirectory;
string ftppath = “file/” + “ftp.exe”;
Process p = new Process();
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
p.StartInfo.FileName = “123”;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
StreamWriter sw = p.StandardInput;