Problem with Wing FTP and Perl NET::SMTP::Foreign client

Please post here if you have problems in using Wing FTP Server.
OneDollar
Posts: 6
Joined: Fri Jul 03, 2015 3:21 pm

Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by OneDollar »

We are running Wing FTP Server 4.4.7, Secure edition on a Linux platform.

We have a client who is trying to upload files to our Wing FTP server using a Perl script that uses the NET::SFTP::Foreign SFTP client. They have the same script working on several other SFTP servers, but when they upload files to ours it returns the error "Couldn't setstat remote file (fsetstat): packet unsupported." The uploaded file is created, but is empty.

I've built my own (much smaller) Perl script based on theirs (I don't know Perl, so apologies if I've made any glaring oversights) and I can reproduce the error. The code (with substituted connection details) is below:

Code: Select all

use strict;
use warnings;
use Net::SFTP::Foreign;

# Uncomment the below to enable debugging:
#$Net::SFTP::Foreign::debug = -1;

# Create the SFTP connection
my $host = "sftp.ourserver.co.uk";
my $user = "useraccount";
my $port = 22;
print "Attempting to connect to $host:$port\n";
my $sftp = Net::SFTP::Foreign->new($host, user=>$user, port=>$port,) or do
{
  print "Cannot connect via SFTP: $!\n";
  exit 1;
};
print "Connected via SFTP\n";


# Upload file 
my $startingPath = $sftp->cwd;
# Regex to make sure paths have a '/' on the end
$startingPath =~ s!/*$!/!;
my $fullRemotePath;
my $remoteUploadPath = "DataIn/";
my $localFileName = "test.txt";
my $uploadReady = 1;

print "Starting upload process\n";
$sftp->setcwd($startingPath . $remoteUploadPath);
if ($sftp->error)
{
  my $tmpError = $sftp->error;
  print ("Unable to change to the remote path: $tmpError\n");
  $uploadReady = 0;
}
else
{   
  $fullRemotePath = $startingPath . $remoteUploadPath;
}

if ($uploadReady == 1)
{
  print ("Starting to upload $localFileName to $fullRemotePath" . $localFileName . " on $host\n");
  unless ($sftp->put($localFileName, $fullRemotePath . $localFileName))
  {
    my $tmpError = $sftp->error;
    print "Unable to upload $localFileName to $host: $tmpError\n";
  } 
  else
  { 
    print "File uploaded\n";
  }
}

# All done so exit the script
undef $sftp;
printf ">>>>>>> Script Finished <<<<<<<\n";
exit 0;
When I run the above I get the following printed to the terminal:

Code: Select all

[root@localhost ~]# perl sftpPerl.pl
Attempting to connect to sftp.ourserver.co.uk:22
useraccount@sftp.ourserver.co.uk's password:
Connected via SFTP
Starting upload process
Starting to upload test.txt to /DataIn/test.txt on sftp.ourserver.co.uk
Unable to upload test.txt to sftp.ourserver.co.uk: Couldn't setstat remote file (fsetstat): packet unsupported.
Connection to sftp.ourserver.co.uk closed by remote host.
>>>>>>> Script Finished <<<<<<<
The Wing FTP logs show the following (IP addresses blanked out):

Code: Select all

[02] Mon, 06 Jul 2015 14:48:57 (0017332) Connected from xxx.xxx.xxx.xxx (local address yyy.yyy.yyy.yyy, port 22)
[01] Mon, 06 Jul 2015 14:48:59 (0017332) SSH session receive user name:useraccount
[01] Mon, 06 Jul 2015 14:48:59 (0017332) SSH session receive password of user useraccount
[01] Mon, 06 Jul 2015 14:48:59 (0017332) User/password authentication OK.
[01] Mon, 06 Jul 2015 14:48:59 (0017332) SSH authentication completed successfully. Client information:SSH-2.0-OpenSSH_5.3
[01] Mon, 06 Jul 2015 14:48:59 (0017332) The user useraccount logged in successfully via SSH.
[07] Mon, 06 Jul 2015 14:48:59 (0017332) SSH_FXP_INIT: client SSH version 3
[08] Mon, 06 Jul 2015 14:48:59 (0017332) SSH_FXP_VERSION: server SSH version 3
[07] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_REALPATH: path
[08] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_NAME: path
[07] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_REALPATH: path /DataIn/
[08] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_NAME: path /DataIn/
[07] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_STAT: path: /DataIn.
[08] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_ATTRS: Filesize: 4096, UserID: 0, GroupID: 0, Permissions: 16877, Last modify time:1436189776.
[07] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_OPEN: path /DataIn/test.txt
[07] Mon, 06 Jul 2015 14:49:00 (0017332) Transfer starting for  /DataIn/test.txt
[08] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_HANDLE: /DataIn/test.txt has been opened.
[07] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_UNSUPPORTED_PACKET: packet unsupported.
[08] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_STATUS: packet unsupported.
[07] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_CLOSE: path /DataIn/test.txt
[07] Mon, 06 Jul 2015 14:49:00 (0017332) File  Transfer OK, 0 Bytes has been received,0.000 KB/S
[08] Mon, 06 Jul 2015 14:49:00 (0017332) SSH_FXP_STATUS: /DataIn/test.txt has been closed.
[02] Mon, 06 Jul 2015 14:49:00 (0017332) Closed session,disconnected from xxx.xxx.xxx.xxx
Finally I can also enable debugging on NET::SFTP::Foreign. When I do I get the following output from the terminal:

Code: Select all

[root@localhost ~]# perl sftpPerl.pl
Attempting to connect to sftp.ourserver.co.uk:22
#4305 1436189770.00000 new: ssh cmd: ssh -p 22 -l useraccount sftp.ourserver.co.uk -s sftp

#4305 1436189770.00000 _queue_msg: queueing msg len: 5, code:1, id:3 ... [1]
00 00 00 05 01 00 00 00 03                                                                      | .........
#4305 1436189770.00000 _get_msg: waiting for message... [1]
#4305 1436189770.00000 _do_io_unix: _do_io connected: 1
#4305 1436189770.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189770.00000 _do_io_unix: _do_io write queue: 9, syswrite: 9, max: 65536
00 00 00 05 01 00 00 00 03                                                                      | .........
#4305 1436189770.00000 _do_io_unix: _do_io select(-,-,-, undef)
useraccount@sftp.ourserver.co.uk's password:
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 9, total read: 9
00 00 00 05 02 00 00 00 03                                                                      | .........
#4305 1436189776.00000 _get_msg: got it!, len:5, code:2, id:-, status: -
02 00 00 00 03                                                                                  | .....
Connected via SFTP
#4305 1436189776.00000 _rel2abs: _rel2abs: '' --> ''
#4305 1436189776.00000 _queue_msg: queueing msg len: 9, code:16, id:0 ... [1]
00 00 00 09 10 00 00 00 00 00 00 00 00                                                          | .............
#4305 1436189776.00000 _get_msg: waiting for message... [1]
#4305 1436189776.00000 _do_io_unix: _do_io connected: 1
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io write queue: 13, syswrite: 13, max: 65536
00 00 00 09 10 00 00 00 00 00 00 00 00                                                          | .............
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 27, total read: 27
00 00 00 17 68 00 00 00 00 00 00 00 01 00 00 00 01 2f 00 00 00 01 2f 00 00 00 00                | ....h............/..../....
#4305 1436189776.00000 _get_msg: got it!, len:23, code:104, id:0, status: -
68 00 00 00 00 00 00 00 01 00 00 00 01 2f 00 00 00 01 2f 00 00 00 00                            | h............/..../....
Starting upload process
#4305 1436189776.00000 _rel2abs: _rel2abs: '/DataIn/' --> '/DataIn/'
#4305 1436189776.00000 _queue_msg: queueing msg len: 17, code:16, id:1 ... [1]
00 00 00 11 10 00 00 00 01 00 00 00 08 2f 44 61 74 61 49 6e 2f                                  | ............./DataIn/
#4305 1436189776.00000 _get_msg: waiting for message... [1]
#4305 1436189776.00000 _do_io_unix: _do_io connected: 1
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io write queue: 21, syswrite: 21, max: 65536
00 00 00 11 10 00 00 00 01 00 00 00 08 2f 44 61 74 61 49 6e 2f                                  | ............./DataIn/
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 39, total read: 39
00 00 00 23 68 00 00 00 01 00 00 00 01 00 00 00 07 2f 44 61 74 61 49 6e 00 00 00 07 2f 44 61 74 | ...#h............/DataIn..../Dat
61 49 6e 00 00 00 00                                                                            | aIn....
#4305 1436189776.00000 _get_msg: got it!, len:35, code:104, id:1, status: -
68 00 00 00 01 00 00 00 01 00 00 00 07 2f 44 61 74 61 49 6e 00 00 00 07 2f 44 61 74 61 49 6e 00 | h............/DataIn..../DataIn.
00 00 00                                                                                        | ...
#4305 1436189776.00000 _rel2abs: _rel2abs: '/DataIn' --> '/DataIn'
#4305 1436189776.00000 _queue_msg: queueing msg len: 16, code:17, id:2 ... [1]
00 00 00 10 11 00 00 00 02 00 00 00 07 2f 44 61 74 61 49 6e                                     | ............./DataIn
#4305 1436189776.00000 _get_msg: waiting for message... [1]
#4305 1436189776.00000 _do_io_unix: _do_io connected: 1
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io write queue: 20, syswrite: 20, max: 65536
00 00 00 10 11 00 00 00 02 00 00 00 07 2f 44 61 74 61 49 6e                                     | ............./DataIn
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 41, total read: 41
00 00 00 25 69 00 00 00 02 00 00 00 0f 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 41 | ...%i..........................A
ed 55 9a 84 1b 55 9a 84 1b                                                                      | .U...U...
#4305 1436189776.00000 _get_msg: got it!, len:37, code:105, id:2, status: -
69 00 00 00 02 00 00 00 0f 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 41 ed 55 9a 84 | i..........................A.U..
1b 55 9a 84 1b                                                                                  | .U...
Starting to upload test.txt to /DataIn/test.txt on sftp.ourserver.co.uk
#4305 1436189776.00000 _rel2abs: _rel2abs: '/DataIn/test.txt' --> '/DataIn/test.txt'
#4305 1436189776.00000 _rel2abs: _rel2abs: '/DataIn/test.txt' --> '/DataIn/test.txt'
#4305 1436189776.00000 _queue_msg: queueing msg len: 37, code:3, id:3 ... [1]
00 00 00 25 03 00 00 00 03 00 00 00 10 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74 00 00 00 | ...%........./DataIn/test.txt...
1a 00 00 00 04 00 00 01 a4                                                                      | .........
#4305 1436189776.00000 _get_msg: waiting for message... [1]
#4305 1436189776.00000 _do_io_unix: _do_io connected: 1
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io write queue: 41, syswrite: 41, max: 65536
00 00 00 25 03 00 00 00 03 00 00 00 10 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74 00 00 00 | ...%........./DataIn/test.txt...
1a 00 00 00 04 00 00 01 a4                                                                      | .........
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 31, total read: 31
00 00 00 1b 66 00 00 00 03 00 00 00 12 30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74    | ....f........0 /DataIn/test.txt
#4305 1436189776.00000 _get_msg: got it!, len:27, code:102, id:3, status: -
66 00 00 00 03 00 00 00 12 30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74                | f........0 /DataIn/test.txt
#4305 1436189776.00000 open: new remote file '/DataIn/test.txt' open, rid:
30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74                                           | 0 /DataIn/test.txt
#4305 1436189776.00000 _queue_msg: queueing msg len: 35, code:10, id:4 ... [1]
00 00 00 23 0a 00 00 00 04 00 00 00 12 30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74 00 | ...#.........0 /DataIn/test.txt.
00 00 04 00 00 01 a4                                                                            | .......
#4305 1436189776.00000 _get_msg: waiting for message... [1]
#4305 1436189776.00000 _do_io_unix: _do_io connected: 1
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io write queue: 39, syswrite: 39, max: 65536
00 00 00 23 0a 00 00 00 04 00 00 00 12 30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74 00 | ...#.........0 /DataIn/test.txt.
00 00 04 00 00 01 a4                                                                            | .......
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 40, total read: 40
00 00 00 24 65 00 00 00 04 00 00 00 08 00 00 00 13 70 61 63 6b 65 74 20 75 6e 73 75 70 70 6f 72 | ...$e............packet unsuppor
74 65 64 2e 00 00 00 00                                                                         | ted.....
#4305 1436189776.00000 _get_msg: got it!, len:36, code:101, id:4, status: 8
65 00 00 00 04 00 00 00 08 00 00 00 13 70 61 63 6b 65 74 20 75 6e 73 75 70 70 6f 72 74 65 64 2e | e............packet unsupported.
00 00 00 00                                                                                     | ....
#4305 1436189776.00000 _set_status: _set_status code: 8, str: packet unsupported.
#4305 1436189776.00000 _set_error: _set_err code: 25, str: Couldn't setstat remote file (fsetstat): packet unsupported.
#4305 1436189776.00000 DESTROY: Net::SFTP::Foreign::FileHandle=GLOB(0x13b5328)->DESTROY called (sftp: Net::SFTP::Foreign=HASH(0xfed120))
#4305 1436189776.00000 _queue_msg: queueing msg len: 27, code:4, id:5 ... [1]
00 00 00 1b 04 00 00 00 05 00 00 00 12 30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74    | .............0 /DataIn/test.txt
#4305 1436189776.00000 _get_msg: waiting for message... [1]
#4305 1436189776.00000 _do_io_unix: _do_io connected: 1
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io write queue: 31, syswrite: 31, max: 65536
00 00 00 1b 04 00 00 00 05 00 00 00 12 30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74    | .............0 /DataIn/test.txt
#4305 1436189776.00000 _do_io_unix: _do_io select(-,-,-, undef)
#4305 1436189776.00000 _do_io_unix: _do_io read sysread: 21, total read: 21
00 00 00 11 65 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00                                  | ....e................
#4305 1436189776.00000 _get_msg: got it!, len:17, code:101, id:5, status: 0
65 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00                                              | e................
#4305 1436189776.00000 _close: closing file handle, return: 1, rid:
30 20 2f 44 61 74 61 49 6e 2f 74 65 73 74 2e 74 78 74                                           | 0 /DataIn/test.txt
Unable to upload test.txt to sftp.ourserver.co.uk: Couldn't setstat remote file (fsetstat): packet unsupported.
#4305 1436189776.00000 DESTROY: Net::SFTP::Foreign=HASH(0xfed120)->DESTROY called (current pid: 4305, disconnect_by_pid: )
#4305 1436189776.00000 disconnect: Net::SFTP::Foreign=HASH(0xfed120)->disconnect called (ssh pid: 4306)
#4305 1436189776.00000 _conn_lost: _conn_lost
Connection to sftp.ourserver.co.uk closed by remote host.
>>>>>>> Script Finished <<<<<<<
Is this a bug in Wing FTP, or is there a setting somewhere I need to change to make this work?

Thanks in advance.
Last edited by OneDollar on Fri Jul 24, 2015 3:13 pm, edited 1 time in total.
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by FTP »

First, please upgrade to the latest version 4.4.9, because the new version fixed a bug about the SFTP upload
OneDollar
Posts: 6
Joined: Fri Jul 03, 2015 3:21 pm

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by OneDollar »

I've upgraded to 4.4.9 now, but I'm still seeing the same errors.
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by FTP »

OK, you can find the answer in this web page:
http://search.cpan.org/~salva/Net-SFTP- ... Foreign.pm" rel="nofollow

Some servers forbid the SFTP setstat operation used by the put method for replicating the file permissions and time-stamps on the remote side. As a work around you can just disable the feature:

Code: Select all

$sftp->put($local_file, $remote_file, copy_perms => 0, copy_time => 0);
OneDollar
Posts: 6
Joined: Fri Jul 03, 2015 3:21 pm

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by OneDollar »

OK, thanks. The problem is I don't think I can convince the client to change their script (they use the same script to upload to lots of other servers). When it says "Some servers forbid the SFTP setstat operation", do you know if that means the SFTP software or the underlying Linux install? Is there anything we can change on our side to make this work without editing the script?
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by FTP »

Yes, I guess that's the only way to solve such issue, and it won't effect anything when uploading file.
OneDollar
Posts: 6
Joined: Fri Jul 03, 2015 3:21 pm

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by OneDollar »

But is it WingFTP that's forbidding the setstat operation, or is that something I can configure in Linux?
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by FTP »

OK, I did some test with your script, it seems that the Perl script sent the SSH command "SSH_FXP_FSETSTAT", but WingFTP only supports the command "SSH_FXP_SETSTAT" currently.

Anyway, we will improve the SFTP compatibility and let it support the command "SSH_FXP_FSETSTAT" in the next version, thanks for your report!
OneDollar
Posts: 6
Joined: Fri Jul 03, 2015 3:21 pm

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by OneDollar »

Great, thanks for the help! Any idea when that's likely to come out?
OneDollar
Posts: 6
Joined: Fri Jul 03, 2015 3:21 pm

Re: Problem with Wing FTP and Perl NET::SMTP::Foreign client

Post by OneDollar »

Hi, sorry but the client is pushing me for time scales or we're going to have to switch to another solution. Any idea when a version that supports this is likely to come out?
Post Reply