Я пытаюсь создать метод, который загружает файл на FTP-сервер.Это работает нормально, как это
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential("xxxx", "xxxx");
client.UploadFile("ftp://127.0.0.1/demo.xml", WebRequestMethods.Ftp.UploadFile, "D:\\Test\\demo.xml");
}
, но если удаленный файл уже существует до загрузки, я получаю эту ошибку
Удаленный сервер возвратил ошибку: (550) Файл недоступен(например, файл не найден, нет доступа).
Когда я удаляю файл с сервера и снова загружаю его, он работает нормально.
Я хочу использовать то же самоеимя (перезаписать файл).Есть ли возможность удалить его оттуда, если он существует, а затем загрузить его?
Это журнал
Step into: Stepping over property 'VigoBAS.Core.Helpers.FTP.get_LocalPath'. To step into properties or operators, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
System.Net Information: 0 : [2956] FtpWebRequest#44665200::.ctor(ftp://127.0.0.1/oslo-Bruker-Fnr.xml)
System.Net Information: 0 : [2956] FtpWebRequest#44665200::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Created connection from 127.0.0.1:61008 to 127.0.0.1:21.
System.Net Information: 0 : [2956] Associating FtpWebRequest#44665200 with FtpControlStream#20222386
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [220-FileZilla Server 0.9.60 beta
220-written by Tim Kosse (tim.kosse@filezilla-project.org)
220 Please visit https://filezilla-project.org/]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [USER TestFtpUser]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [331 Password required for testftpuser]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [PASS ********]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [230 Logged on]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [202 UTF8 mode is always enabled. No need to send this command.]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [PWD]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [257 "/" is current directory.]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [TYPE I]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [200 Type set to I]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [PASV]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [227 Entering Passive Mode (127,0,0,1,221,45)]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Sending command [STOR oslo-Bruker-Fnr.xml]
System.Net Information: 0 : [2956] FtpControlStream#20222386 - Received response [550 Permission denied]
System.Net Information: 0 : [2956] FtpWebRequest#44665200::(Releasing FTP connection#20222386.)
System.Net Error: 0 : [2956] Exception in FtpWebRequest#44665200::GetRequestStream - The remote server returned an error: (550) File unavailable (e.g., file not found, no access)..
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetRequestStream()