robinrodricks / FluentFTP

An FTP and FTPS client for .NET & .NET Standard, optimized for speed. Provides extensive FTP commands, File uploads/downloads, SSL/TLS connections, Automatic directory listing parsing, File hashing/checksums, File permissions/CHMOD, FTP proxies, FXP support, UTF-8 support, Async/await support, Powershell support and more. Written entirely in C#.
MIT License
3.1k stars 651 forks source link

UploadFile error when destination folder is empty #315

Closed olivierSOW closed 5 years ago

olivierSOW commented 6 years ago

FTP OS: Unix

FTP Server: ftpd

Computer OS: Raspberry 3+

Cannot upload file via uploadFile when destination folder is empty (no file present before uploading) The command "NLST" get "550 No files found." response and then throw an exception

Code:

m_ftpClient = new FluentFTP.FtpClient(m_initStruct.host, m_initStruct.username, m_initStruct.password);
m_ftpClient.Encoding = System.Text.Encoding.UTF8; //need to accent in name even if server return it not reconize option
m_ftpClient.ListingParser = FluentFTP.FtpParser.Legacy; //trying without, same issue
m_ftpClient.Connect();

if(m_ftpClient.FileExists(destinationPath)) { /* destinationPath=usb/key1/seexport/2018-07-05_16-33-55 Les chats sont-ils les rois d'Internet_-Les félins insoumis/S1_/16-34-11_Micro 01_HC.mp3 */
    m_ftpClient.DeleteFile(destinationPath);
}
else { 
    //force create parent folder because reateRemoteDirectory parameter crash
    m_ftpClient.CreateDirectory(
        GetParentPath(destinationPath)
    );
}
    m_ftpClient.UploadFile(
        sourcePath /* sourcePath=d:\temp\seexport\temp\20180705_(PRIVATE)Les chats sont-ils les rois d'Internet__20180713_152928.0594\S1_\16-34-11_Micro 01_HC.mp3 */
        , destinationPath
        , FluentFTP.FtpExists.Overwrite //tried with differents options, same issue
        , false //createRemoteDirectory crash
        ,FluentFTP.FtpVerify.None //tried with differents options, same issue
);

Logs :

Connect()

Status: Connecting to 192.168.251.251:21 Response: 220 seraspi FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready. Command: USER copycat Response: 331 Password required for copycat. Command: PASS ** Response: 230 User copycat logged in. Response: 230- Response: 230- The programs included with the Debian GNU/Linux system are free software; Response: 230- the exact distribution terms for each program are described in the Response: 230- individual files in /usr/share/doc//copyright. Response: 230- Response: 230- Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent Response: 230- permitted by applicable law. Command: FEAT Response: 500 'FEAT': command not understood. Status: Text encoding: System.Text.UTF8Encoding Command: OPTS UTF8 ON Response: 500 'OPTS UTF8 ON': command not understood. Command: SYST Response: 215 UNIX Type: L8 (Linux) Status: Auto-detected UNIX listing parser

DirectoryExists("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_ Response: 550 usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_: No such file or directory.

DirectoryExists("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis Response: 550 usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis: No such file or directory.

DirectoryExists("usb/key1/seexport")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport Response: 550 usb/key1/seexport: No such file or directory.

DirectoryExists("usb/key1")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1 Response: 250 CWD command successful. Command: CWD /home/copycat Response: 250 CWD command successful.

CreateDirectory("usb/key1/seexport", True)

DirectoryExists("usb/key1")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1 Response: 250 CWD command successful. Command: CWD /home/copycat Response: 250 CWD command successful.

DirectoryExists("usb/key1/seexport")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport Response: 550 usb/key1/seexport: No such file or directory. Status: CreateDirectory usb/key1/seexport Command: MKD usb/key1/seexport Response: 257 "usb/key1/seexport" directory created.

CreateDirectory("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis", True)

DirectoryExists("usb/key1/seexport")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport Response: 250 CWD command successful. Command: CWD /home/copycat Response: 250 CWD command successful.

DirectoryExists("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis Response: 550 usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis: No such file or directory. Status: CreateDirectory usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis Command: MKD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis Response: 257 "usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis" directory created.

CreateDirectory("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_", True)

DirectoryExists("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis Response: 250 CWD command successful. Command: CWD /home/copycat Response: 250 CWD command successful.

DirectoryExists("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory. Command: CWD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_ Response: 550 usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_: No such file or directory. Status: CreateDirectory usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_ Command: MKD usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_ Response: 257 "usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_" directory created. SeexportClient.127.0.0.1_57916 INFO copying file to usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_/16-34-11_Micro 01_HC.mp3

FileExists("usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_/16-34-11_Micro 01_HC.mp3")

GetWorkingDirectory()

Command: PWD Response: 257 "/home/copycat" is current directory.

GetNameListing("/home/copycat/usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_")

Command: TYPE I Response: 200 Type set to I.

OpenPassiveDataStream(AutoPassive, "NLST /home/copycat/usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_", 0)

Command: EPSV Response: 229 Extended Passive Mode OK (|||54671|) Status: Connecting to 192.168.251.251:54671 Command: NLST /home/copycat/usb/key1/seexport/2018-07-0516-33-55 Les chats sont-ils les rois d'Internet-Les félins insoumis/S1_ Response: 550 No files found. Status: Disposing FtpSocketStream...

CloseDataStream()

Exception levée : 'FluentFTP.FtpCommandException' dans FluentFTP.dll

olivierSOW commented 6 years ago

I can upload file in same situation with filezilla

olivierSOW commented 6 years ago

I do a fork with a workaround into LowLevel class. Certainly not the best solution:

if (!(reply = Execute(command)).Success) { if(command.StartsWith("NLST ") && reply.Code=="550" && reply.Message== "No files found.") { //workaround for ftpd which response "550 No files found" when folder exists but is empty } else { stream.Close(); throw new FtpCommandException(reply); } }

Alexeyrnd commented 6 years ago

Same trouble. Problem solved?

dendism commented 5 years ago

still not fixed in latest version (19.2.3).. UploadFile throws an exception if used with FtpExists.Overwrite or FtpExists.Skip and the destination directory is empty.. if there is any file, it works as expected

olivierSOW commented 5 years ago

You can use my branch, i fix it but only for my way of use. I think i don’t fix it completly.

robinrodricks commented 5 years ago

Is this fixed in the latest release?

robinrodricks commented 5 years ago

Please reply if you still have this issue.

dendism commented 5 years ago

i tried it with 2 different ftp servers - one was FileZilla ftp server - here it works like a charm. but the second one is proftpd (sadly used by the client) and there it is not working. here's more details about the server:

ProFTPD 1.2.10 Server Command line to send FEAT 211-Features: 211-MDTM 211-REST STREAM 211-SIZE 211 End

dunno, if the problem is related to the proftpd or just bcoz it's a very old version. anyway as a workaround i just keep there empty text file :) i can send you privately credentials, if you want to try it by yourself.

olivierSOW commented 5 years ago

Sorry, i was busy.

Like as already said, i fix the error by myself. You can find the fix in my branch.

I didn’t try your new version at this time and have currently no time to do it.

Sorry