Skip to main content
Can Unidata do SFTP?  I have written socket language interfaces to SMTP and others.  Is it the same type of interface for SFTP?  I'm having a hard time finding the direct interface commands it needs.  I can connect and get info from the socket but it never asks for User name/Password.

Most of the google results point to using WinSCP, but i'd rather do the commands myself.  Anyone been down this path?

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
Can Unidata do SFTP?  I have written socket language interfaces to SMTP and others.  Is it the same type of interface for SFTP?  I'm having a hard time finding the direct interface commands it needs.  I can connect and get info from the socket but it never asks for User name/Password.

Most of the google results point to using WinSCP, but i'd rather do the commands myself.  Anyone been down this path?

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------

David,

I am also curious, on how others have done sftp.

If you have access to the command from the server, you should be able to EXECUTE the command from BASIC.

Try the following at the OS cmd prompt to verify:

C:\\Users\\mrajkowski>sftp

usage: sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]

          [-D sftp_server_path] [-F ssh_config] [-i identity_file]

          [-J destination] [-l limit] [-o ssh_option] [-P port]

          [-R num_requests] [-S program] [-s subsystem | sftp_server]

          destination  

 

If that is not on your system, you may want to look at calling Python module for the sftp.

Yet, if someone went to the extent of writing an sftp client,  please share it here.



------------------------------
Mike Rajkowski
support
Rocket Internal - All Brands
DENVER CO US
------------------------------

David,

I am also curious, on how others have done sftp.

If you have access to the command from the server, you should be able to EXECUTE the command from BASIC.

Try the following at the OS cmd prompt to verify:

C:\\Users\\mrajkowski>sftp

usage: sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]

          [-D sftp_server_path] [-F ssh_config] [-i identity_file]

          [-J destination] [-l limit] [-o ssh_option] [-P port]

          [-R num_requests] [-S program] [-s subsystem | sftp_server]

          destination  

 

If that is not on your system, you may want to look at calling Python module for the sftp.

Yet, if someone went to the extent of writing an sftp client,  please share it here.



------------------------------
Mike Rajkowski
support
Rocket Internal - All Brands
DENVER CO US
------------------------------
Mike thanks for your response.

Yes I can do the sftp from the CMD prompt on the windows 2019 server.  But you can't auto feed the password (something to do with security, go figure).  There might be a way to do it with a SSH Key file created with the password embedded.  Still trying to figure that one out too.  Not sure how to feed the -i identity_file  i'm having a hard time finding any docs on those command line arguments.  Any help would be appreciated.

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
Mike thanks for your response.

Yes I can do the sftp from the CMD prompt on the windows 2019 server.  But you can't auto feed the password (something to do with security, go figure).  There might be a way to do it with a SSH Key file created with the password embedded.  Still trying to figure that one out too.  Not sure how to feed the -i identity_file  i'm having a hard time finding any docs on those command line arguments.  Any help would be appreciated.

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
David,
 
I have not worked with the sftp module for Python, but I have worked with ftp, and it should be possible to do a similar solution:




------------------------------
Mike Rajkowski
support
Rocket Internal - All Brands
DENVER CO US
------------------------------
Can Unidata do SFTP?  I have written socket language interfaces to SMTP and others.  Is it the same type of interface for SFTP?  I'm having a hard time finding the direct interface commands it needs.  I can connect and get info from the socket but it never asks for User name/Password.

Most of the google results point to using WinSCP, but i'd rather do the commands myself.  Anyone been down this path?

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
Hi David,
Sftp uses SSH under the hood, so you'd have to implement all that too.  A bit trickier than establishing a socket connection to port 25 and sending "EHLO" down the pipe. :-)  I haven't dealt with this on Windows, but I can say a couple things generally.  I use an "identity file" (private key) option to get around the interactive username/password login.  WinSCP has that ability too.  It also has good scripting support and functionality to produce a template script for you.  Check out their documentation for details.  If neither whatever Win Server sftp built-in utility nor WinSCP fit your bill, I'd do like Mike suggested and look into python integration.

------------------------------
John Sherman
Developer
Concord Servicing Corporation
Scottsdale AZ US
------------------------------
Hi David,
Sftp uses SSH under the hood, so you'd have to implement all that too.  A bit trickier than establishing a socket connection to port 25 and sending "EHLO" down the pipe. :-)  I haven't dealt with this on Windows, but I can say a couple things generally.  I use an "identity file" (private key) option to get around the interactive username/password login.  WinSCP has that ability too.  It also has good scripting support and functionality to produce a template script for you.  Check out their documentation for details.  If neither whatever Win Server sftp built-in utility nor WinSCP fit your bill, I'd do like Mike suggested and look into python integration.

------------------------------
John Sherman
Developer
Concord Servicing Corporation
Scottsdale AZ US
------------------------------
Thanks John and Mike,

I'm leaning towards the identity_file just need to find a good how to create a private key doc.  If i can't get that to work with straight sftp commands i will resort to using WinSCP.  So far all my research has sent me in that direction.

I've never done python, but always eager to learn new things.  The question is, "does it support sftp?"  Mike's example was an ftp script, but as you know sftp is a different animal.

I'll keep everyone posted when i get it figured out.

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
Can Unidata do SFTP?  I have written socket language interfaces to SMTP and others.  Is it the same type of interface for SFTP?  I'm having a hard time finding the direct interface commands it needs.  I can connect and get info from the socket but it never asks for User name/Password.

Most of the google results point to using WinSCP, but i'd rather do the commands myself.  Anyone been down this path?

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
Hi,

If you have PHP on that machine you can create a simply sftp program using sftpclass.php (downloadble from internet)

Here is a sample.

<?php
require 'sftpclass.php';

$host = $argv[1];
$port = $argv[2];
$user = $argv[3];
$pswd = $argv[4];
$remote_folder = $argv[5];
$local_folder = $argv[6];
$del_remote = $argv[7];
$echo = $argv[8];

if ($host=='') die ("Missing Host Name/IP");
if ($port=='') die ("Missing Port Number");
if ($user=='') die ("Missing User Name");
if ($pswd=='') die ("Missing Password");
if ($remote_folder == "") die ("Missing Remote Folder");
if ($local_folder == "") die ("Missing Local Folder");

try
{
    if ($echo) echo "Connecting to $host\\n";
    $sftp = new SFTPConnection($host, $port);
    $sftp->login($user, $pswd);
    if ($echo) echo "Scanning $remote_folder\\n";
    $files = $sftp->scanFilesystem($remote_folder);
    $noOfFiles=0;
    foreach ($files as $file) {
       $get=1;
       if ($file == ".") $get=0;
       if ($file == "..") $get=0;
       if ($get) {
           $sftp->receiveFile($remote_folder."/".$file,$local_folder."/".$file);
           if ($echo) echo "Picked up $remote_folder/$file placed in $local_folder\\n";
           if ($del_remote) {
              $sftp->deleteFile($remote_folder."/".$file);
              if ($echo) echo "Deleted $remote_folder/$file\\n";
           }
           $noOfFiles = $noOfFiles + 1;
       }
    }
    if ($echo) echo "Pickedup $noOfFiles\\n";
}
catch (Exception $e)
{
    echo $e->getMessage() . "\\n";
    exit(0);
}
exit($noOfFiles);

?>

Regards, Sam


------------------------------
Sam Powell
President/Developer
Advanced Transportation Systems Inc
Littleton CO US
------------------------------
Hi,

If you have PHP on that machine you can create a simply sftp program using sftpclass.php (downloadble from internet)

Here is a sample.

<?php
require 'sftpclass.php';

$host = $argv[1];
$port = $argv[2];
$user = $argv[3];
$pswd = $argv[4];
$remote_folder = $argv[5];
$local_folder = $argv[6];
$del_remote = $argv[7];
$echo = $argv[8];

if ($host=='') die ("Missing Host Name/IP");
if ($port=='') die ("Missing Port Number");
if ($user=='') die ("Missing User Name");
if ($pswd=='') die ("Missing Password");
if ($remote_folder == "") die ("Missing Remote Folder");
if ($local_folder == "") die ("Missing Local Folder");

try
{
    if ($echo) echo "Connecting to $host\\n";
    $sftp = new SFTPConnection($host, $port);
    $sftp->login($user, $pswd);
    if ($echo) echo "Scanning $remote_folder\\n";
    $files = $sftp->scanFilesystem($remote_folder);
    $noOfFiles=0;
    foreach ($files as $file) {
       $get=1;
       if ($file == ".") $get=0;
       if ($file == "..") $get=0;
       if ($get) {
           $sftp->receiveFile($remote_folder."/".$file,$local_folder."/".$file);
           if ($echo) echo "Picked up $remote_folder/$file placed in $local_folder\\n";
           if ($del_remote) {
              $sftp->deleteFile($remote_folder."/".$file);
              if ($echo) echo "Deleted $remote_folder/$file\\n";
           }
           $noOfFiles = $noOfFiles + 1;
       }
    }
    if ($echo) echo "Pickedup $noOfFiles\\n";
}
catch (Exception $e)
{
    echo $e->getMessage() . "\\n";
    exit(0);
}
exit($noOfFiles);

?>

Regards, Sam


------------------------------
Sam Powell
President/Developer
Advanced Transportation Systems Inc
Littleton CO US
------------------------------
That is very good idea and a great way to do it.

Here is what i've finally came up with.  I went ahead and downloaded WinSCP and had it make my host key and batch file with the command line arguments.

The batch file works great.  Now i've created a control record to house the host/user/password/host key etc. and creating the batch file on the fly sending the log to a specific file in order to review the process automatically.

Seems to be working good, I was hoping to not have to install any 3rd party software, but time is not on my side to create an SFTP unidata version right now.

Thanks to all who jumped in with terrific ideas.

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
That is very good idea and a great way to do it.

Here is what i've finally came up with.  I went ahead and downloaded WinSCP and had it make my host key and batch file with the command line arguments.

The batch file works great.  Now i've created a control record to house the host/user/password/host key etc. and creating the batch file on the fly sending the log to a specific file in order to review the process automatically.

Seems to be working good, I was hoping to not have to install any 3rd party software, but time is not on my side to create an SFTP unidata version right now.

Thanks to all who jumped in with terrific ideas.

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
We also use WinSCP for FTP and sFTP and more,  and the author is very ready to respond to any questions or comments you might have as well.
We literally get replies within 24 hours.

And then batch it up, and pipe the logs to your email so you don't have to monitor it every day.

------------------------------
Will Johnson
Systems Analyst
Rocket Forum Shared Account
------------------------------
Can Unidata do SFTP?  I have written socket language interfaces to SMTP and others.  Is it the same type of interface for SFTP?  I'm having a hard time finding the direct interface commands it needs.  I can connect and get info from the socket but it never asks for User name/Password.

Most of the google results point to using WinSCP, but i'd rather do the commands myself.  Anyone been down this path?

------------------------------
David Green
Computer Programmer
Rocket Forum Shared Account
------------------------------
expect is one way to do if you cant use certs. I never tried on Windows. Expect scripts can handle timeout situations via timeout.The expect scripts can be rock solid with the right code. The username and password stored in an os env variable which is passed into expect scripts should be set to null when done. Storing the authentication credentials inside a hashed db is better than putting it in the script. On UV db, parsing and setting the password to null in any COMO or PH file is good to do. SFTP cmd prompts and responses obviously vary, especially a Windows vs NIX server. Be sure to filter out strange charater codes when parsing captured data from expect and whatever shell environment used to execute the expect script. I use custom return codes from the uv basic environment and the expect script to verify things are proceeding correctly.

https://en.m.wikipedia.org/wiki/Expect

https://wiki.tcl-lang.org/page/Expect+for+Windows


------------------------------
Mike Bojaczko
PROGRAMMER ANALYST
US
------------------------------