0

I try to upload files and wrote the following code with the help of FluentFTP:

      clientFluentFTP = new FtpClient(hostname,
                                       username,
                                       password);

      clientFluentFTP.LoadProfile(new FtpProfile
      {
        Host = hostname,
        Credentials = new NetworkCredential(username, password),
        Encryption = FtpEncryptionMode.Explicit,
        Protocols = SslProtocols.Tls12,
        DataConnection = FtpDataConnectionType.PASV, 
        Encoding = Encoding.UTF8,
      }) ;

      clientFluentFTP.ValidateAnyCertificate = true;
      clientFluentFTP.Connect();
      clientFluentFTP.UploadFile(localfile, requestname, FtpRemoteExists.Overwrite,false,FtpVerify.Throw);

I test with my first file (UTF8 encoded) and the result is a zero byte file. No exception is thrown so I assume it is able to verify the transfer. Apparently the transfer is not closed off correctly. And yes, with commandline FTP clients I can transfer the file without problems. No message, no error. Just a zero byte file.

What do I do wrong?

The Log from the code is below.

# Connect()
Status:   Connecting to 46.235.40.106:21
Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
Response: 220-You are user number 3 of 50 allowed.
Response: 220-Local time is now 11:54. Server port: 21.
Response: 220-This is a private system - No anonymous login
Response: 220-IPv6 connections are also welcome on this server.
Response: 220 You will be disconnected after 15 minutes of inactivity.
Status:   Detected FTP server: PureFTPd
Command:  AUTH TLS
Response: 234 AUTH TLS OK.
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,1315097.
Command:  USER ***
Response: 331 User ftp_meteo_wagenborgen.nl OK. Password required
Command:  PASS ***
Response: 230-Your bandwidth usage is restricted
Response: 230 OK. Current restricted directory is /
Command:  PBSZ 0
Response: 200 PBSZ=0
Command:  PROT P
Response: 200 Data protection level set to "private"
Command:  FEAT
Response: 211-Extensions supported:
Response: EPRT
Response: IDLE
Response: MDTM
Response: SIZE
Response: MFMT
Response: REST STREAM
Response: MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
Response: MLSD
Response: AUTH TLS
Response: PBSZ
Response: PROT
Response: UTF8
Response: ESTA
Response: PASV
Response: EPSV
Response: SPSV
Response: ESTP
Response: 211 End.
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 OK, UTF-8 enabled
Command:  SYST
Response: 215 UNIX Type: L8

# UploadFile("utils/systeminfoTable.txt", "/web/systeminfoTable.txt", Overwrite, False, Throw)

# FileExists("/web/systeminfoTable.txt")
Command:  SIZE /web/systeminfoTable.txt
Response: 213 1467

# DeleteFile("/web/systeminfoTable.txt")
Command:  DELE /web/systeminfoTable.txt
Response: 250 Deleted /web/systeminfoTable.txt

# OpenWrite("/web/systeminfoTable.txt", Binary)
Command:  TYPE I
Response: 200 TYPE is now 8-bit binary

# OpenPassiveDataStream(PASV, "STOR /web/systeminfoTable.txt", 0)
Command:  PASV
Response: 227 Entering Passive Mode (46,235,40,106,168,24)
Status:   Connecting to 46.235.40.106:43032
Command:  STOR /web/systeminfoTable.txt
Response: 150 Accepted data connection
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,1381567.
Status:   Disposing FtpSocketStream...
Status:   File Verification: PASS

# Dispose()
Status:   Disposing FtpClient object...
Command:  QUIT
Status:   Disposing FtpSocketStream...
Status:   Disposing FtpSocketStream...
Hans Rottier
  • 102
  • 2
  • 12
  • Post FluentFTP log file as well as log files from the commandline FTP clients (running on the same machine as your C# code). – Martin Prikryl Nov 08 '20 at 09:22
  • Thanks for that comment, sorry I forgot the log. However, I found the solution: it must be an ascii file. I would have expectend an automatic detection of that. My bad. – Hans Rottier Nov 08 '20 at 11:08
  • I cannot imagine how using the binary mode could cause the target file be empty. Unless you are using some obscure FTP server. – Martin Prikryl Nov 08 '20 at 14:34
  • True. Neither can I. My remark that the problem is solved is probably not correct because other applications failed as well. The provider uses Pure-FTPd as server. It may be any of the components involved (OpenSSL, wrong configuration, whatever...). So I will remove problem solved. Point is that it most likely is not my code causing the issue. I keep on looking, maybe do a provider switch. I will modify my own answer below. – Hans Rottier Nov 09 '20 at 15:15
  • 1
    This is not a coding issue. It had to do with the provider configuration. After I changed provider the problem was gone. – Hans Rottier Nov 13 '20 at 19:01

1 Answers1

-1

Ah... The default setting is binary and should be ascii. So I added:

  clientFluentFTP.UploadDataType = FtpDataType.ASCII;

Problem solved.See my comment under the problem description

It had nothing to do with coding. I changed provider because of a configuration issue and the problem was gone.

Hans Rottier
  • 102
  • 2
  • 12