在FluentFTP上载零字节文件

问题描述

我尝试上传文件,并在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);

我测试了我的第一个文件(UTF8编码),结果是一个零字节文件。 没有异常被抛出,因此我认为它能够验证传输。显然,传输未正确关闭。是的,使用命令行FTP客户端,我可以毫无问题地传输文件。没有消息,没有错误。只是一个零字节的文件

我该怎么办?

下面是代码中的日志。

# 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...

解决方法

Ah ...默认设置为二进制,应为ascii。 所以我加了:

  clientFluentFTP.UploadDataType = FtpDataType.ASCII;

问题已解决。请参阅问题描述下的我的评论

它与编码无关。 由于配置问题,我更改了提供程序,但问题消失了。