【问题标题】:zero byte file on FluentFTP uploadFluentFTP 上传时的零字节文件
【发布时间】:2020-11-08 08:55:37
【问题描述】:

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

【问题讨论】:

  • 发布 FluentFTP 日志文件以及来自命令行 FTP 客户端的日志文件(与您的 C# 代码在同一台机器上运行)。
  • 感谢您的评论,抱歉我忘记了日志。但是,我找到了解决方案:它必须是一个 ascii 文件。我本来希望自动检测到这一点。我的错。
  • 我无法想象使用二进制模式如何导致目标文件为空。除非你使用一些不起眼的 FTP 服务器。
  • 是的。我也不能。我说问题已解决可能不正确,因为其他应用程序也失败了。提供商使用 Pure-FTPd 作为服务器。它可能是涉及的任何组件(OpenSSL、错误的配置,等等……)。所以我会删除解决的问题。关键是很可能不是我的代码导致了这个问题。我继续寻找,也许做一个供应商切换。我将在下面修改我自己的答案。
  • 这不是编码问题。它与提供程序配置有关。在我更换提供商后,问题就消失了。

标签: c# ftp fluentftp


【解决方案1】:

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

  clientFluentFTP.UploadDataType = FtpDataType.ASCII;

问题已解决。在问题描述下查看我的评论

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

【讨论】:

    猜你喜欢
    • 2013-12-22
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2013-06-03
    相关资源
    最近更新 更多