Почему бы мне не получить ответ от FTP-сервера? - PullRequest
1 голос
/ 23 января 2020

В то время как я вернулся, я создал приложение, которое использовало FluentFTP для просмотра и загрузки файлов с FTP-сервера. В течение последнего месяца приложение начинало зависать при выполнении любого действия FTP с использованием библиотеки. Я проверил журналы, сгенерированные FluentFTP, и действия были выполнены успешно, но они не были утилизированы должным образом. Я пробовал оба GetListing и Download и столкнулся с той же ошибкой. Если посмотреть на трассировку стека, то, как представляется, общая точка сбоя происходит на GetReply(), что в исходном коде гласит:

Извлекает ответ с сервера. Не выполняйте этот метод, если вы не уверены, что ответ отправлен, т. Е. Вы выполнили команду. Это приведет к зависанию кода на неопределенный срок, ожидая ответа от сервера, который никогда не приходит.

Мне кажется, что по какой-то причине я не получаю ответ от FTP-сервера, когда должен быть. Тем не менее, я в недоумении, почему. Я могу без проблем использовать автономный FTP-клиент, такой как WinSCP. Баребонки. NET FtpWebRequest и FtpWebResponse также работают. Я попробовал тестировать дома, и он работает нормально. Я проверил с моим отделом ИТ, и они утверждают, что они не сделали никаких недавних изменений. Я не изменил свой код. Это происходит независимо от сервера, к которому я подключаюсь.

Любая помощь будет принята с благодарностью.

Вот мой тестовый код. (Я запустил это под vanilla. NET. Тайм-аут также произошел под ядром. NET, он не вызывал никаких исключений):

    private static void ListViaFluentFtp()
    {
        FtpTrace.AddListener(new ConsoleTraceListener());
        var ftpClient = new FtpClient("test.rebex.net", "demo", "password");
        ftpClient.Connect();
        ftpClient.GetListing("/"); //TimeOutException here
    }

Вот журнал, сгенерированный FleuntFTP:

# Connect()
Status:   Connecting to 195.144.107.198:21
Response: 220 Microsoft FTP Service
Status:   Detected FTP server: WindowsServerIIS
Command:  USER demo
Response: 331 Password required for demo.
Command:  PASS ***
Response: 230 User logged in.
Command:  FEAT
Response: 211-Extended features supported:
Response: LANG EN*
Response: UTF8
Response: AUTH TLS;TLS-C;SSL;TLS-P;
Response: PBSZ
Response: PROT C;P;
Response: CCC
Response: HOST
Response: SIZE
Response: MDTM
Response: REST STREAM
Response: 211 END
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Command:  SYST
Response: 215 Windows_NT

# GetListing("/", Auto)
Command:  TYPE I
Response: 200 Type set to I.

# OpenPassiveDataStream(AutoPassive, "LIST /", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||1033|)
Status:   Connecting to 195.144.107.198:1033
Command:  LIST /
Response: 125 Data connection already open; Transfer starting.
+---------------------------------------+
Listing:  10-27-15  03:46PM       <DIR>          pub
Listing:  04-08-14  03:09PM                  403 readme.txt
-----------------------------------------
Status:   Disposing FtpSocketStream...

# CloseDataStream()
The thread 0x5b4 has exited with code 0 (0x0).
Status:   Disposing FtpSocketStream...
Exception thrown: 'System.TimeoutException' in FluentFTP.dll
An unhandled exception of type 'System.TimeoutException' occurred in FluentFTP.dll
Timed out trying to read data from the socket stream!

Вот трассировка стека:

System.TimeoutException
  HResult=0x80131505
  Message=Timed out trying to read data from the socket stream!
  Source=FluentFTP
  StackTrace:
   at FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at FluentFTP.FtpSocketStream.ReadLine(Encoding encoding)
   at FluentFTP.FtpClient.GetReply()
   at FluentFTP.FtpClient.CloseDataStream(FtpDataStream stream)
   at FluentFTP.FtpDataStream.Close()
   at FluentFTP.FtpClient.GetListingInternal(String listcmd, FtpListOption options, Boolean retry)
   at FluentFTP.FtpClient.GetListing(String path, FtpListOption options)
   at FluentFTP.FtpClient.GetListing(String path)
   at FtPNetTest.Program.Main(String[] args) in C:\Users\jevensen\source\repos\FtpTest\FtPNetTest\Program.cs:line 18

Вот журнал для загрузки (это было до последнего обновления, которое фактически игнорирует время ожидания):

# Connect()
Status:   Connecting to 195.144.107.198:21
Response: 220 Microsoft FTP Service
Status:   Detected FTP server: WindowsServerIIS
Command:  USER demo
Response: 331 Password required for demo.
Command:  PASS ***
Response: 230 User logged in.
Command:  FEAT
Response: 211-Extended features supported:
Response: LANG EN*
Response: UTF8
Response: AUTH TLS;TLS-C;SSL;TLS-P;
Response: PBSZ
Response: PROT C;P;
Response: CCC
Response: HOST
Response: SIZE
Response: MDTM
Response: REST STREAM
Response: 211 END
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Command:  SYST
Response: 215 Windows_NT

# Download("/readme.txt")

# OpenRead("/readme.txt", Binary, 0)
Command:  TYPE I
Response: 200 Type set to I.

# OpenPassiveDataStream(AutoPassive, "RETR /readme.txt", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||1027|)
Status:   Connecting to 195.144.107.198:1027
Command:  RETR /readme.txt
Response: 125 Data connection already open; Transfer starting.
Status:   Disposing FtpSocketStream...
The thread 0x4830 has exited with code 0 (0x0).
The thread 0x3f88 has exited with code 0 (0x0).
The thread 0x4c20 has exited with code 0 (0x0).
Status:   Disposing FtpSocketStream...
Status:   Disposing FtpSocketStream...
Exception thrown: 'FluentFTP.FtpException' in FluentFTP.dll
An unhandled exception of type 'FluentFTP.FtpException' occurred in FluentFTP.dll
Error while downloading the file from the server. See InnerException for more info.

трассировка стека:

This exception was originally thrown at this call stack:
    FluentFTP.FtpSocketStream.Read(byte[], int, int)
    FluentFTP.FtpSocketStream.ReadLine(System.Text.Encoding)
    FluentFTP.FtpClient.GetReply()
    FluentFTP.FtpClient.DownloadFileInternal(string, System.IO.Stream, long, System.Action<FluentFTP.FtpProgress>)

РЕДАКТИРОВАТЬ: Здесь журналы уровня 1 от WinSCP делают то же самое:

. 2020-01-23 08:55:54.627 --------------------------------------------------------------------------
. 2020-01-23 08:55:54.628 WinSCP Version 5.13 (Build 8172) (OS 10.0.18362 - Windows 10 Enterprise)
. 2020-01-23 08:55:54.629 Configuration: C:\Users\***\Downloads\WinSCP\WinSCP.ini
. 2020-01-23 08:55:54.629 Log level: Debug 1
. 2020-01-23 08:55:54.629 Local account: OFFICE\***
. 2020-01-23 08:55:54.629 Working directory: C:\Users\***\Downloads\WinSCP
. 2020-01-23 08:55:54.629 Process ID: 5352
. 2020-01-23 08:55:54.631 Command-line: "C:\Users\***\Downloads\WinSCP\WinSCP.exe" 
. 2020-01-23 08:55:54.639 Time zone: Current: GMT-8, Standard: GMT-8 (Pacific Standard Time), DST: GMT-7 (Pacific Daylight Time), DST Start: 3/8/2020, DST End: 11/1/2020
. 2020-01-23 08:55:54.639 Login time: Thursday, January 23, 2020 8:55:54 AM
. 2020-01-23 08:55:54.639 --------------------------------------------------------------------------
. 2020-01-23 08:55:54.640 Session name: demo@test.rebex.net (Ad-Hoc site)
. 2020-01-23 08:55:54.640 Host name: test.rebex.net (Port: 21)
. 2020-01-23 08:55:54.640 User name: demo (Password: Yes, Key file: No, Passphrase: No)
. 2020-01-23 08:55:54.640 Transfer Protocol: FTP
. 2020-01-23 08:55:54.640 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2020-01-23 08:55:54.640 Disable Nagle: No
. 2020-01-23 08:55:54.640 Proxy: None
. 2020-01-23 08:55:54.640 Send buffer: 262144
. 2020-01-23 08:55:54.640 UTF: Auto
. 2020-01-23 08:55:54.640 FTPS: None [Client certificate: No]
. 2020-01-23 08:55:54.640 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2020-01-23 08:55:54.640 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2020-01-23 08:55:54.640 Cache directory changes: Yes, Permanent: Yes
. 2020-01-23 08:55:54.640 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2020-01-23 08:55:54.640 Timezone offset: 0h 0m
. 2020-01-23 08:55:54.640 --------------------------------------------------------------------------
. 2020-01-23 08:55:54.757 Session upkeep
. 2020-01-23 08:55:54.897 Connecting to test.rebex.net ...
. 2020-01-23 08:55:54.963 Connected with test.rebex.net. Waiting for welcome message...
< 2020-01-23 08:55:55.299 220 Microsoft FTP Service
> 2020-01-23 08:55:55.299 USER demo
< 2020-01-23 08:55:55.468 331 Password required for demo.
> 2020-01-23 08:55:55.468 PASS ********
< 2020-01-23 08:55:55.635 230 User logged in.
> 2020-01-23 08:55:55.636 SYST
. 2020-01-23 08:55:55.804 The server is probably running Windows, assuming that directory listing timestamps are affected by DST.
< 2020-01-23 08:55:55.804 215 Windows_NT
> 2020-01-23 08:55:55.804 FEAT
< 2020-01-23 08:55:55.970 211-Extended features supported:
< 2020-01-23 08:55:55.970  LANG EN*
< 2020-01-23 08:55:55.970  UTF8
< 2020-01-23 08:55:55.970  AUTH TLS;TLS-C;SSL;TLS-P;
< 2020-01-23 08:55:55.970  PBSZ
< 2020-01-23 08:55:55.970  PROT C;P;
< 2020-01-23 08:55:55.970  CCC
< 2020-01-23 08:55:55.970  HOST
< 2020-01-23 08:55:55.970  SIZE
< 2020-01-23 08:55:55.973  MDTM
< 2020-01-23 08:55:55.973  REST STREAM
< 2020-01-23 08:55:55.973 211 END
> 2020-01-23 08:55:55.973 OPTS UTF8 ON
< 2020-01-23 08:55:56.140 200 OPTS UTF8 command successful - UTF8 encoding now ON.
. 2020-01-23 08:55:56.140 Session upkeep
. 2020-01-23 08:55:56.193 Connected
. 2020-01-23 08:55:56.193 Got reply 1 to the command 1
. 2020-01-23 08:55:56.193 --------------------------------------------------------------------------
. 2020-01-23 08:55:56.193 Using FTP protocol.
. 2020-01-23 08:55:56.197 Doing startup conversation with host.
. 2020-01-23 08:55:56.197 Session upkeep
> 2020-01-23 08:55:56.207 PWD
< 2020-01-23 08:55:56.373 257 "/" is current directory.
. 2020-01-23 08:55:56.373 Got reply 1 to the command 16
. 2020-01-23 08:55:56.373 Getting current directory name.
. 2020-01-23 08:55:56.440 Retrieving directory listing...
> 2020-01-23 08:55:56.440 TYPE A
< 2020-01-23 08:55:56.607 200 Type set to A.
> 2020-01-23 08:55:56.612 PASV
< 2020-01-23 08:55:56.781 227 Entering Passive Mode (195,144,107,198,4,10).
> 2020-01-23 08:55:56.781 LIST -a
. 2020-01-23 08:55:56.781 Connecting to 195.144.107.198:1034 ...
< 2020-01-23 08:55:56.952 150 Opening ASCII mode data connection.
. 2020-01-23 08:55:57.119 Data connection closed
. 2020-01-23 08:55:57.119 12-03-15  08:14PM       <DIR>          aspnet_client
. 2020-01-23 08:55:57.119 10-27-15  03:46PM       <DIR>          pub
. 2020-01-23 08:55:57.119 04-08-14  03:09PM                  403 readme.txt
< 2020-01-23 08:55:57.119 226 Transfer complete.
. 2020-01-23 08:55:57.119 Directory listing successful
. 2020-01-23 08:55:57.122 Got reply 1 to the command 2
. 2020-01-23 08:55:57.122 Detecting timezone difference...
. 2020-01-23 08:55:57.122 Retrieving file information...
> 2020-01-23 08:55:57.122 PWD
< 2020-01-23 08:55:57.310 257 "/" is current directory.
> 2020-01-23 08:55:57.310 CWD /readme.txt
< 2020-01-23 08:55:57.481 550 The filename, directory name, or volume label syntax is incorrect. 
> 2020-01-23 08:55:57.481 TYPE I
< 2020-01-23 08:55:57.646 200 Type set to I.
> 2020-01-23 08:55:57.646 SIZE /readme.txt
< 2020-01-23 08:55:57.814 213 403
> 2020-01-23 08:55:57.814 MDTM /readme.txt
< 2020-01-23 08:55:57.980 213 20140408140939
. 2020-01-23 08:55:57.980 Retrieving file information successful
. 2020-01-23 08:55:57.980 Got reply 1 to the command 1024
. 2020-01-23 08:55:57.983 Timezone difference of +9 detected using file /readme.txt (Listing: 2014-04-08T23:09:00.000Z, UTF: 2014-04-08T14:09:00.000Z)
. 2020-01-23 08:55:57.984 ..;D;0;1899-12-30T08:00:00.000Z;0;"" [0];"" [0];---------;0
. 2020-01-23 08:55:57.984 aspnet_client;D;0;2015-12-03T19:14:00.000Z;1;"" [0];"" [0];---------;0
. 2020-01-23 08:55:57.984 pub;D;0;2015-10-27T14:46:00.000Z;1;"" [0];"" [0];---------;0
. 2020-01-23 08:55:57.984 readme.txt;-;403;2014-04-08T14:09:00.000Z;1;"" [0];"" [0];---------;0
. 2020-01-23 08:55:57.984 Session upkeep
. 2020-01-23 08:55:58.012 Startup conversation with host finished.
. 2020-01-23 08:55:58.156 Session upkeep
. 2020-01-23 08:55:58.658 Session upkeep
. 2020-01-23 08:55:59.158 Session upkeep
. 2020-01-23 08:55:59.656 Session upkeep
. 2020-01-23 08:56:00.157 Session upkeep
. 2020-01-23 08:56:00.612 Copying 1 files/directories to local directory "C:\Users\***\Documents\" - total size: 403
. 2020-01-23 08:56:00.612   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: Yes; Mask: *.*
. 2020-01-23 08:56:00.612   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2020-01-23 08:56:00.612   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2020-01-23 08:56:00.615 File: '/readme.txt' [2014-04-08T14:09:00.000Z] [403]
. 2020-01-23 08:56:00.655 Copying "/readme.txt" to local directory started.
. 2020-01-23 08:56:00.655 Binary transfer mode selected.
. 2020-01-23 08:56:00.655 Starting download of /readme.txt
. 2020-01-23 08:56:00.656 Asking user:
. 2020-01-23 08:56:00.656 **Overwrite local file 'readme.txt'?**
. 2020-01-23 08:56:00.656 
. 2020-01-23 08:56:00.656 Destination directory already contains file 'readme.txt'.
. 2020-01-23 08:56:00.656 Choose, if you want to overwrite the file or skip this transfer and keep existing file.
. 2020-01-23 08:56:00.656  
. 2020-01-23 08:56:00.656 New:          403 bytes, 4/8/2014 7:09 AM
. 2020-01-23 08:56:00.656 Existing:     403 bytes, 4/8/2014 7:09:39 AM ()
. 2020-01-23 08:56:01.161 Session upkeep
. 2020-01-23 08:56:01.658 Session upkeep
. 2020-01-23 08:56:01.908 Transfer progress: Transferred: 0, Left: 0:00:00, CPS: 0/s
> 2020-01-23 08:56:01.911 TYPE I
< 2020-01-23 08:56:02.079 200 Type set to I.
> 2020-01-23 08:56:02.079 PASV
< 2020-01-23 08:56:02.245 227 Entering Passive Mode (195,144,107,198,4,6).
> 2020-01-23 08:56:02.245 RETR readme.txt
. 2020-01-23 08:56:02.245 Connecting to 195.144.107.198:1030 ...
< 2020-01-23 08:56:02.597 150 Opening BINARY mode data connection.
. 2020-01-23 08:56:02.746 Data connection closed
< 2020-01-23 08:56:02.746 226 Transfer complete.
. 2020-01-23 08:56:02.747 Preserving timestamp [2014-04-08T14:09:00.000Z]
. 2020-01-23 08:56:02.747 Download successful
. 2020-01-23 08:56:02.747 Got reply 1 to the command 4
. 2020-01-23 08:56:02.748 Transfer done: '/readme.txt' => 'C:\Users\***\Documents\readme.txt' [403]
. 2020-01-23 08:56:02.748 Copying finished: Transferred: 403, Elapsed: 0:00:02, CPS: 2,583/s
. 2020-01-23 08:56:03.163 Session upkeep
. 2020-01-23 08:56:03.660 Session upkeep
. 2020-01-23 08:56:04.156 Session upkeep
. 2020-01-23 08:56:04.654 Session upkeep
. 2020-01-23 08:56:05.157 Session upkeep
. 2020-01-23 08:56:05.661 Session upkeep
. 2020-01-23 08:56:06.174 Got reply 1004 to the command 4
. 2020-01-23 08:56:06.174 Disconnected from server
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...