我创建了一个小型 Windows 窗体应用程序来将文件上传到我们客户的一个 ftp 站点。但是我遇到的问题是,当我在本地计算机上运行此应用程序时,它会成功上传文件。但是如果我在我们的服务器上运行这个程序,我会收到这个错误消息;
远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问该文件),在此行 'objFTPRequest.GetRequestStream();'。
有人知道为什么吗?我需要配置防火墙还是什么?这是我的代码;
FileInfo objFile = new FileInfo(filename);
FtpWebRequest objFTPRequest;
// Create FtpWebRequest object
objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/outbox/" + objFile.Name));
// Set Credintials
objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
// By default KeepAlive is true, where the control connection is
// not closed after a command is executed.
objFTPRequest.KeepAlive = false;
// Set the data transfer type.
objFTPRequest.UseBinary = true;
// Set content length
objFTPRequest.ContentLength = objFile.Length;
// Set request method
objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;
// Set buffer size
int intBufferLength = 16 * 1024;
byte[] objBuffer = new byte[intBufferLength];
// Opens a file to read
FileStream objFileStream = objFile.OpenRead();
// Get Stream of the file
Stream objStream = objFTPRequest.GetRequestStream();
int len = 0;
while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0)
{
// Write file Content
objStream.Write(objBuffer, 0, len);
}
objStream.Close();
objFileStream.Close();