看看这个线程。
此外,为了避免幕后的 PWD,您可以使用 .Net FTP 客户端,例如edtFtpNet,如下所示:
var ftp = new FTPClient();
ftp.BytesTransferred += new BytesTransferredHandler((o, e) => { Console.WriteLine("Remote Path: " + e.RemotePath + ", Remote File: " + e.RemoteFile + ", Bytes transfered: " + e.ByteCount); });
ftp.TransferStartedEx += new TransferHandler((o, e) => { Console.WriteLine("FTP Transfer started!"); });
ftp.TransferCompleteEx += new TransferHandler((o, e) => { Console.WriteLine("FTP Transfer completed!"); });
try
{
ftp.RemoteHost = FTP_HOST;
ftp.ConnectMode = FTPConnectMode.ACTIVE;
ftp.Timeout = 120000;
ftp.Connect();
ftp.Login(FTP_USER, FTP_PWD);
ftp.TransferType = FTPTransferType.BINARY;
ftp.Put(GetBytes("file contents go here!"), Guid.NewGuid().ToString() + ".txt");
}
catch (Exception e)
{
Console.WriteLine("Error:" + e.ToString());
}
finally
{
ftp.Quit();
Console.WriteLine("FTP Quit!");
}