Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnection leads to loss of WorkingDirectory #850

Closed
AleMcKee opened this issue Feb 23, 2022 · 4 comments
Closed

Reconnection leads to loss of WorkingDirectory #850

AleMcKee opened this issue Feb 23, 2022 · 4 comments

Comments

@AleMcKee
Copy link

FTP OS: Windows

FTP Server: WindowsServerIIS

Computer OS: Windows 10 20H2 (Build 19042.1526)

FluentFTP Version: 37.0.1.

Bug:

In the end, I run the following code (this is copied together a bit to keep it short):

var _client = new FtpClient("10.9.10.11", "21341", @"DOMAIN\username", "******");
_client?.Connect();

var targetDir = "/BLOB/03 MyData/03 DataChanges";

if (!_client.DirectoryExists(targetDir))
    _client.CreateDirectory(targetDir);
_client.SetWorkingDirectory(targetDir);

foreach(var ftpFile in _client.GetListing())
{
    var destFile = Path.Combine(@"D:\TOOL\LOGS\MyData\DataChanges\", RemotePaths.GetFtpFileName(ftpFile.FullName));
    await _client.DownloadFileAsync(ftpFile.Name, destFile, FtpLocalExists.Overwrite);

    // Doing things with the file that may take some time

    _client.MoveFile(ftpFile.Name, $"./Archiv/{RemotePaths.GetFtpFileName(ftpFile.FullName)}", FtpRemoteExists.Overwrite);
}

This code also works perfectly. But in rare cases moving the file to the archive does not work. I have tried to trace this with the log.

It seems that the client sometimes loses the connection, and then reestablishes it. However, it loses the information of the current WorkingDirectory which causes the move not to work.

Logs :

# Connect()
Status:   Connecting to 10.9.10.11:21341
Response: 220 Microsoft FTP Service
Status:   Detected FTP server: WindowsServerIIS
Command:  USER DOMAIN\username
Response: 331 Password required
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
Status:   Listing parser set to: Windows

# DirectoryExists("BLOB/03 MyData/03 DataChanges")
Command:  PWD
Response: 257 "/" is current directory.
Command:  CWD BLOB/03 MyData/03 DataChanges
Response: 250 CWD command successful.
Command:  CWD /
Response: 250 CWD command successful.

# SetWorkingDirectory("BLOB/03 MyData/03 DataChanges")
Command:  CWD BLOB/03 MyData/03 DataChanges
Response: 250 CWD command successful.

# GetListing(null, Auto)
Command:  PWD
Response: 257 "/BLOB/03 MyData/03 DataChanges" is current directory.
Command:  TYPE I
Response: 200 Type set to I.

# OpenPassiveDataStream(AutoPassive, "LIST /BLOB/03 MyData/03 DataChanges", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||21398|)
Status:   Connecting to 10.9.10.11:21398
Command:  LIST /BLOB/03 MyData/03 DataChanges
Response: 125 Data connection already open; Transfer starting.
+---------------------------------------+
Listing:  02-14-22  04:54PM       <DIR>          Archiv
Listing:  02-11-22  09:36AM       <DIR>          Error
Listing:  02-21-22  12:05PM                98621 TestFile-MyData-Export-21-02-2022.xlsx
-----------------------------------------
Status:   Disposing FtpSocketStream...

# CloseDataStream()
Response: 226 Transfer complete.
Status:   Disposing FtpSocketStream...
Status:   Confirmed format Windows

# DownloadFileAsync("D:\TOOL\LOGS\MyData\DataChanges\TestFile-MyData-Export-21-02-2022.xlsx", "TestFile-MyData-Export-21-02-2022.xlsx", Overwrite, None)

# OpenReadAsync("TestFile-MyData-Export-21-02-2022.xlsx", Binary, 0, 0)

# GetFileSizeAsync("TestFile-MyData-Export-21-02-2022.xlsx", -1)
Command:  SIZE TestFile-MyData-Export-21-02-2022.xlsx
Response: 213 98621

# OpenPassiveDataStreamAsync(AutoPassive, "RETR TestFile-MyData-Export-21-02-2022.xlsx", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||21351|)
Status:   Connecting to 10.9.10.11:21351
Command:  RETR TestFile-MyData-Export-21-02-2022.xlsx
Response: 125 Data connection already open; Transfer starting.
Status:   Disposing FtpSocketStream...
Response: 226 Transfer complete.

# MoveFile("TestFile-MyData-Export-21-02-2022.xlsx", "./Archiv/TestFile-MyData-Export-21-02-2022.xlsx", Overwrite)

# FileExists("TestFile-MyData-Export-21-02-2022.xlsx")
Status:   Testing connectivity using Socket.Poll()...
Status:   Disposing FtpSocketStream...

# Connect()
Status:   Connecting to 10.9.10.11:21341
Response: 220 Microsoft FTP Service
Status:   Detected FTP server: WindowsServerIIS
Command:  USER DOMAIN\username
Response: 331 Password required
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
Status:   Listing parser set to: Windows
Command:  SIZE /BLOB/03 MyData/03 DataChanges/TestFile-MyData-Export-21-02-2022.xlsx
Response: 213 98621

# FileExists("./Archiv/TestFile-MyData-Export-21-02-2022.xlsx")
Command:  PWD
Response: 257 "/" is current directory.
Command:  SIZE /Archiv/TestFile-MyData-Export-21-02-2022.xlsx
Response: 550 The system cannot find the path specified. 

# Rename("TestFile-MyData-Export-21-02-2022.xlsx", "./Archiv/TestFile-MyData-Export-21-02-2022.xlsx")
Command:  RNFR /TestFile-MyData-Export-21-02-2022.xlsx
Response: 550 The system cannot find the file specified. 
Command:  QUIT
Response: 221 Goodbye.
Status:   Disposing FtpSocketStream...

# Dispose()
Status:   Disposing FtpClient object...
Status:   Disposing FtpSocketStream...
@robinrodricks
Copy link
Owner

Yes working directory is not restored.

@robinrodricks
Copy link
Owner

Added to the bucket list. We will pick this up as and when we have free time. Comment on this issue if you want us to prioritize it. Thanks!

@robinrodricks robinrodricks closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2022
@FanDjango
Copy link
Collaborator

This has been done. Removing from the bucket list.

@robinrodricks
Copy link
Owner

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants