0

我尝试上传文件并在 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...
4

1 回答 1

-1

啊...默认设置是二进制,应该是ascii。所以我补充说:

  clientFluentFTP.UploadDataType = FtpDataType.ASCII;

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

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

于 2020-11-08T11:02:09.860 回答