How to upload the file to another SFTP server from shell channel by using Jsch? - shell

Step 1: Session connect
....
session.connect()
Step 2: Shell channel
channel = session.openChannel("shell");
Step 3: Execute ssh commands to login Unix server and go to the required path cd /logs/server
PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience
channel.connect();
shellStream.println(command);
shellStream.flush();
step 4: Get the file from Unix server and put into SFTP:
code to connect sftp channel and put the file from unix server to sftp.
So I want to upload the file (logs/server/server.log) from Unix server (which I logged in using shell channel) to SFTP server.
Both source and destination are remote.
Is it possible to do by using JSch?

An SFTP protocol (let alone JSch SFTP library) has no support for transfers between two remote servers.
If you have a shell access to one of the servers, you can try to transfer the files by using a command-line (OpenSSH) sftp client on the server. It's doable. Problematic is an authentication part, as it's non-interactive session. You would have to use an unencrypted private key, an agent forwarding or sshpass.
Obvious and simple implementation is to download the files from the "Unix" server to a local machine and then upload them to the "SFTP" server. But you need to use the SFTP channel, not the shell channel, for the download.

Related

Transfer Files through FTP in Windows Batch Scripts having Private Key

I am using these command to transfer a file to an SFTP location.It has an private key(Puttygen) with
passphrase.
open ftp://%1%:%2%#%3%/ -explicittls -certificate="32:4b:5e:a7:05:b9:e4:2d:7d:44:cb:c1:0e:ee:0e:17"-privatekey=D:\SSIS_DEV\DBTeam\Transfer\Rural\Private.ppk
put %4%
I am getting a timeout error while connecting.
exit
You want to use SFTP, but use FTP (ftp://) protocol in the session URL.
Use sftp:// instead:
open sftp://%1%:%2%#%3%/
FTP and SFTP are two completely different and incompatible protocols. You get the timeout, because you are trying to connect to the FTP port, which the server does not listen on.

Automatic download via ftp [duplicate]

I need to connect to a host with username, password, implicit TLS encryption and port number to download files to a folder daily on windows server standard. Is there a third party command-line application that I could download, install and use for this (preferably free)? I'm not absolutely sure if this could be done with Windows ftp and if it can, could it be done in batch file?
I am trying NcFTP but I'm not sure if it supports encryption either.
I was given specific credentials, I have no control over the server. I have only instructions on how to access and download the files with FileZilla client over TLS. I need to schedule a routine that does this job for me since I don't want to manually do this every day. I can manage myself on this I only need a tool that could do this job over command-line.
You can use WinSCP, it supports both scripting and TLS/SSL.
See automating file transfers to FTP server.
A simple batch file to download files over an explicit TLS/SSL (note the ftpes://) with WinSCP looks like:
winscp.com /log=c:\path\ftp.log /command ^
"open ftpes://user:password#example.com/" ^
"get /home/user/* c:\destination\" ^
"exit"
You can have the batch file generated by WinSCP GUI for you.
For scheduling, simply use the Windows Scheduler.
For details see scheduling file transfers to FTP server.
(I'm the author of WinSCP)
Similarly for an upload: Schedule an automatic FTP upload on Windows with WinSCP
You can use sftp to get files. But you need to have an SSH server installed on remote host (OpenSSH is free).
Then you can use putty tools (free) psftp.exe or pscp.exe to upload/download files in encripted format.
Link for putty tools download: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Link for OpenSSH download: http://www.openssh.com/

Downloading a file from FTP using kettle

I was trying to download a file form FTP server(Remote machine) using pentaho kettle (Get a file with FTP), I can able to do that in my local machine. But when i try to deploy the app in jboss web server it fails to download resulting in a error "Error getting files from FTP : Login incorrect."
But everything seems to be correct regarding the login details.
Did i have configure any where else in the server? Please help.
There are several things you could check in this case:
Check that the security settings of the remote FTP server allows for the machine that runs the job to establish an FTP connection. If you have access to the server, try the following command to ensure that the server has access:
telnet <your-remote-ftp-server-host> 21
# Or try:
telnet <your-remote-ftp-server-host> 22
Verify that the remote FTP server respects FTP connection requests, otherwise try SFTP (Get a file with FTP & Get a file with SFTP are two entirely different job steps in Kettle)
Wherever you are fetching your FTP credentials from (ideally a configuration file), test that the credentials are properly read by the job in the relevant scope - use the Write To Log step for that matter

How to schedule an automatic FTP download on Windows?

I need to connect to a host with username, password, implicit TLS encryption and port number to download files to a folder daily on windows server standard. Is there a third party command-line application that I could download, install and use for this (preferably free)? I'm not absolutely sure if this could be done with Windows ftp and if it can, could it be done in batch file?
I am trying NcFTP but I'm not sure if it supports encryption either.
I was given specific credentials, I have no control over the server. I have only instructions on how to access and download the files with FileZilla client over TLS. I need to schedule a routine that does this job for me since I don't want to manually do this every day. I can manage myself on this I only need a tool that could do this job over command-line.
You can use WinSCP, it supports both scripting and TLS/SSL.
See automating file transfers to FTP server.
A simple batch file to download files over an explicit TLS/SSL (note the ftpes://) with WinSCP looks like:
winscp.com /log=c:\path\ftp.log /command ^
"open ftpes://user:password#example.com/" ^
"get /home/user/* c:\destination\" ^
"exit"
You can have the batch file generated by WinSCP GUI for you.
For scheduling, simply use the Windows Scheduler.
For details see scheduling file transfers to FTP server.
(I'm the author of WinSCP)
Similarly for an upload: Schedule an automatic FTP upload on Windows with WinSCP
You can use sftp to get files. But you need to have an SSH server installed on remote host (OpenSSH is free).
Then you can use putty tools (free) psftp.exe or pscp.exe to upload/download files in encripted format.
Link for putty tools download: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Link for OpenSSH download: http://www.openssh.com/

Using WinSCP to access a remote SFTP server

I am using SFTP client(WinSCP) to get into a remote server and retrieve some files. I could not get to the SFTP server when I use WinSCP in a Windows-7 machine; but it works good when I try it from an XP machine. Can anyone think of what might be wrong. Any help appreciated!
I am also including the error screenshot, if that helps
Can anyone please help!
This could be some problem with your firewall. Check it if you are blocking WinSCP.
Quoting WinSCP documentation on the error message Server unexpectedly closed network connection:
If you get this error message while connecting to your server, it is
most usually caused by the server not being able to run some process
necessary to support your session. Always try to connect with another
SSH (SFTP) client to find, if it is server or client related problem.
Possibilities are:
Shell.
Your account may not be allowed to start a shell at all. With some servers (like OpenSSH or Sun SSH), you may need to be allowed to
start a shell, even if using SFTP protocol.
Also some servers refuse to start a shell if your password has expired or your account was terminated.
Some shells do not work with non-interactive sessions. The same it true for some configurations (or profiles used) for otherwise
working shells. This commonly exhibits with SCP protocol with
associated error message "Error skipping startup message. Your shell
is probably incompatible with the application (BASH is recommended)."
Try to force bash shell explicitly on SCP/Shell page of Advanced Site
Settings dialog. Using SFTP protocol instead of SCP is another option.
OpenSSH server may fail to start shell when chroot is configured, but not possible (e.g. due to group writeable permissions
to chroot directory).
Some environments require specific permissions (e.g. 755) to files like .profile or .bashrc.
SFTP server.
Your account may not be able to start SFTP server binary (e.g. /bin/sftp-server) or the binary is not present on your server.
Your SSH server may also lack the SFTP subsystem.
SSH server:
Your SSH server, particularly OpenSSH, may not be able to access the server key files, due to an incorrect permissions.

Resources