我正在接手一个完全手工完成的过程,并试图将其自动化。一步是将纯文本文件FTP到FTP服务器上的特定目录。我搜索时看到的所有内容都是将文件丢弃在服务器上,而不是将其放在特定目录中。我得到的错误是文件名不被允许,除了它是手动FTP的相同名称。以下是我的代码。我错过了什么?
LocalFile = Path.GetFileName(TheFile)
URI = TheHost & RemoteDir & LocalFile
TheFtpClient = CType(FtpWebRequest.Create(URI), FtpWebRequest)
TheFtpClient.Credentials = New NetworkCredential(UserName, PassWord)
TheFtpClient.KeepAlive = False
TheFtpClient.Method = WebRequestMethods.Ftp.UploadFile
FileReader = New StreamReader(TheFile)
FileContents = Encoding.UTF8.GetBytes(FileReader.ReadToEnd())
FileReader.Close()
TheFtpClient.ContentLength = FileContents.Length
RequestStream = TheFtpClient.GetRequestStream()
RequestStream.Write(FileContents, 0, FileContents.Length)
RequestStream.Close()
TheResponse = CType(TheFtpClient.GetResponse(), FtpWebResponse)
Console.WriteLine("[" & TheResponse.StatusDescription & "]")