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
------------------------------
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
------------------------------
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
------------------------------
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
------------------------------
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:
FTP Example
One example of extending Rocket MultiValue with Python is providing a way to do FTP from the Rocket MultiValue Application.
Python has modules that can do this, and in this example we will work with ftplib
Note that since I may share this notebook, I will not hard code the password.
from getpass import getpass
passwd = getpass("Enter the password")
Enter the password········
Here is a simple example of how to use the ftplib module.
import ftplib
# Note the server name we are connecting to is hard coded.
ftp = ftplib.FTP("dentrpy")
# The Login takes the username and password
ftp.login("mrajkowski", passwd)
ftp.cwd("/tmp/mike")
# Get the contents of the current working directory on the ftp server.
ftp.retrlines('LIST')
# When you are done with the connection, close it!
ftp.quit()
-rw-r--r-- 1 44797 534 7769 May 18 16:48 Untitled4.ipynb -rw-r--r-- 1 0 0 0 May 18 16:46 testfile
'221 Goodbye.'
Creating your own ftp function.
Instead of calling each method of the ftplib from a Rocket MultiValue BASIC Program, I recomend that you write a function, that will do what you want, and will only need to be called once for each transfer.
import os
import ftplib
def myFtpPut( serverName, userName, password, local_path, filename, remote_dir ):
try:
if local_path != '':
filepath = local_path + filename
else:
filepath = filename
ftp = ftplib.FTP("dentrpy")
ftp.login(userName, password)
ftp.cwd(remote_dir)
file = open(filepath, "rb")
ftp.storbinary("STOR " + filename, file)
file.close()
ftp.quit()
except Exception as e:
print(str(e))
# Testing out the method, do not copy the following lines to create the myftp.py module.
myFtpPut( "dentrpy", 'mrajkowski', passwd, '', 'Untitled4.ipynb', '/tmp/mike')
print("done")
done
Note that you can now take the above method, and put it into a Python file, in the PP directory of the XDEMO account.
i.e. name the file myFtp
Then in the BASIC code do something like the following:
TESTFTP
HOST = "dentrpy"
USER = "mrajkowski"
CRT "ENTER PASSWORD":;INPUT PASSWD
LOCALPATH = ".\\\\PBP\\\\"
FILENAME = "TESTFTP"
REMOTEPATH = "/tmp"
ST = PyCallFunction('myftp','myFtpPut', HOST, USER, PASSWD, LOCALPATH, FILENAME, REMOTEPATH)
IF @PYEXCEPTIONTYPE = '' THEN
CRT ST
END ELSE
PRINT @PYEXCEPTIONMSG
PRINT @PYEXCEPTIONTRACEBACK
PRINT @PYEXCEPTIONTYPE
END
------------------------------
Mike Rajkowski
support
Rocket Internal - All Brands
DENVER CO US
------------------------------
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
------------------------------
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
------------------------------
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
------------------------------
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
------------------------------
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
------------------------------
If you have PHP on that machine you can create a simply sftp program using sftpclass.php (downloadble from internet)
Here is a sample.
Regards, Sam
------------------------------
Sam Powell
President/Developer
Advanced Transportation Systems Inc
Littleton CO US
------------------------------
If you have PHP on that machine you can create a simply sftp program using sftpclass.php (downloadble from internet)
Here is a sample.
Regards, Sam
------------------------------
Sam Powell
President/Developer
Advanced Transportation Systems Inc
Littleton CO US
------------------------------
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
------------------------------
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 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
------------------------------
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
------------------------------
https://en.m.wikipedia.org/wiki/Expect
https://wiki.tcl-lang.org/page/Expect+for+Windows
------------------------------
Mike Bojaczko
PROGRAMMER ANALYST
US
------------------------------
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.