Solved Copy file from Windows Server to hosted external CentOS server
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
I posted a question similar to this one maybe a couple months ago, either on ML or SW (can't remember, and can't find it!).
Maybe it was answered wherever it was
-
WinSCP is a good SFTP Client for Windows. Filezilla also works nicely too.
Edit: Didn't see the bit about needing something automated. WinSCP definitely does this.
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
I have an on-prem Windows server (Serv2016) with internet access, but cannot be accessed externally.
I also have a virtual private server (CentOS) hosted with Godaddy, with SSH access. I can connect to it just fine with Putty.
Sounds like a job for SCP or SFTP. Run SCP on Windows and automate it to push the file.
-
@scottalanmiller I looked for it and searched here and on SW. I must have forgotten the title I used, and not searching close enough to what I asked. I don't know. I gave it a good 10 minute search. I forgot what all the replies were because I got busy with something else (more important) and had to stick it on the back burner ^_^
-
https://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe
That's the PSCP command for Windows from Putty. You can use that from the command line exactly like SCP.
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
I posted a question similar to this one maybe a couple months ago, either on ML or SW (can't remember, and can't find it!).
Anyways, I'm still at a loss here:
I have an on-prem Windows server (Serv2016) with internet access, but cannot be accessed externally.
I also have a virtual private server (CentOS) hosted with Godaddy, with SSH access. I can connect to it just fine with Putty.
What I'm trying to figure out, is how I can get a file from my on-prem Windows server, to the cloud server, automatically via Scheduled Task?
I'm stuck, and now in a spot where I can work on this some more. But I can't find my previous Post to bring this back into the light and review previous responses.
Of course you can do it directly via SFTP.
Or maybe, create a VPN between the two machines and setup a simple samba server on the CentOS machine and mount it in the windows one.You can also do the transfer via Rsync (it works on windows).
It'a a simple task and you can do it in many ways, you just have to choose what is a better fit for your needs.
-
Excellent, definitely a few seeds planted for me to expand on.
I'll check into WinSCP first to see if there's a way I can get things going.
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Excellent, definitely a few seeds planted for me to expand on.
I'll check into WinSCP first to see if there's a way I can get things going.
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
Install it and make a connection. If it works, you can automate it easily.
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
WinSCP is an SSH tool. SCP and SFTP are part of SSH. If you have SSH, you have SFTP.
-
@JaredBusch said in Copy file from Windows Server to hosted external CentOS server:
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Excellent, definitely a few seeds planted for me to expand on.
I'll check into WinSCP first to see if there's a way I can get things going.
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
Install it and make a connection. If it works, you can automate it easily.
Here's a PS way to automate it.
-
@tiagom said in Copy file from Windows Server to hosted external CentOS server:
@JaredBusch said in Copy file from Windows Server to hosted external CentOS server:
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Excellent, definitely a few seeds planted for me to expand on.
I'll check into WinSCP first to see if there's a way I can get things going.
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
Install it and make a connection. If it works, you can automate it easily.
Here's a PS way to automate it.
Right, the developer of WinSCP made it very flexible.
-
@scottalanmiller said in Copy file from Windows Server to hosted external CentOS server:
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
WinSCP is an SSH tool. SCP and SFTP are part of SSH. If you have SSH, you have SFTP.
That's right. I was thinking FTPS... Two very different things.
-
Or use something like dropbox, placing the file in the dropbox space on the server to sync, and then wget the file.
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
@scottalanmiller said in Copy file from Windows Server to hosted external CentOS server:
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?
WinSCP is an SSH tool. SCP and SFTP are part of SSH. If you have SSH, you have SFTP.
That's right. I was thinking FTPS... Two very different things.
Yup. Just a bit.
Command line SCP or SFTP will work great here. Easy peasy and direct. -
Update:
I got it working cleanly and smoothly with WinSCP. Thanks for the pointer everyone!
If anyone else who comes by this wants to know the procedure:
- Download and install WinSCP on your Windows Server
- Create a basic Scheduled Task, name it, schedule it --> "Start a program", browse to WinSCP.exe.
- Use the argument:
/log=C:\Users\<userProfile>\Desktop\<logName>.log /script=C:\Users\<userProfile>\Desktop\<scriptName>.txt
- Open properties of Scheduled Task, change to run even if not logged in, run with highest privileges, click OK and enter password.
Script Contents
The <scriptName>.txt file can include what you need to happen. My use case was a simple one, and looked like this:
# Connect open sftp://<username>:<password>@123.45.67.890 -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" # Change remote directory cd /var/www/html/pki # Force binary mode transfer option transfer binary # Upload the files to current working directory put "D:\pki\<name>.html" put "D:\pki\<name>.crl" put "D:\pki\<name>+.crl" put "D:\pki\<name>.crl" put "D:\pki\<name>.crt" put "D:\pki\<name>.crt" # Disconnect close # Exit WinSCP exit
Edit: Fixed formatting thanks to JaredBusch's advice below.
-
@Tim_G said in Copy file from Windows Server to hosted external CentOS server:
Note: The above pound symbols do not have a ' after them in the script. I added them on here to avoid formatting issues.
Use the code format by putting 3 backticks in front of and behind the code block. Or escape the # sign by puting a \ in front of it.
Click quote below this post to see it prefaced with > of course, but it lets you see what I mean.
# Connect open sftp://<username>:<password>@123.45.67.890 -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" # Change remote directory cd /var/www/html/pki # Force binary mode transfer option transfer binary # Upload the files to current working directory put "D:\pki\<name>.html" put "D:\pki\<name>.crl" put "D:\pki\<name>+.crl" put "D:\pki\<name>.crl" put "D:\pki\<name>.crt" put "D:\pki\<name>.crt" # Disconnect close # Exit WinSCP exit
# Connect
open sftp://<username>:<password>@123.45.67.890 -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"# Change remote directory
cd /var/www/html/pki# Force binary mode transfer
option transfer binary# Upload the files to current working directory
put "D:\pki<name>.html"
put "D:\pki<name>.crl"
put "D:\pki<name>+.crl"
put "D:\pki<name>.crl"
put "D:\pki<name>.crt"
put "D:\pki<name>.crt"# Disconnect
close# Exit WinSCP
exit -
I'm doing something very similar but cannot get the scheduled task to take my arguments properly.
I'm not sure where it is failing. Scheduled tasks gives no errors, just information.
The only difference is that my server listens on a port other than 22 for SSH. So, I put a :XXXX (port number) in the first command. Still no dice. I'm not sure if it is failing on the contents of the script, or failing because of the arguments.
# Connect open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
The only info I get from event viewer is:
Task Scheduler successfully completed task "\Get Call Recordings" , instance "{13fcf873-f123-46e6-8e80-6ce90b57638c}" , action "C:\Program Files (x86)\WinSCP\WinSCP.exe" with return code 0. 1111
-
@fuznutz04 said in Copy file from Windows Server to hosted external CentOS server:
I'm doing something very similar but cannot get the scheduled task to take my arguments properly.
I'm not sure where it is failing. Scheduled tasks gives no errors, just information.
The only difference is that my server listens on a port other than 22 for SSH. So, I put a :XXXX (port number) in the first command. Still no dice. I'm not sure if it is failing on the contents of the script, or failing because of the arguments.
# Connect open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
The only info I get from event viewer is:
Task Scheduler successfully completed task "\Get Call Recordings" , instance "{13fcf873-f123-46e6-8e80-6ce90b57638c}" , action "C:\Program Files (x86)\WinSCP\WinSCP.exe" with return code 0. 1111
See if you can connect normally.
Open up a command prompt and run winscp.exe.
Then type just:
open sftp://<username>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 <hostkey>"
If you can connect this way, by it prompting you to enter a username, then...
it might be that you may be using an unsupported character in your password... preventing you from including the password in the line you posted.
If the script actually runs, and you are using "/log=<path><log file>.log in the argument, you can check that log.
-
So that works properly if I run it through command prompt. (meaning, it will open WinSCP and login successfully. ) However, for the scheduled task, it appears that it isnt even attempting to read that script.
Note: my password is all normal letters for this test.
-
@fuznutz04 said in Copy file from Windows Server to hosted external CentOS server:
So that works properly if I run it through command prompt. (meaning, it will open WinSCP and login successfully. ) However, for the scheduled task, it appears that it isnt even attempting to read that script.
Note: my password is all normal letters for this test.
What happens if you, in CMD enter in to a WinSCP.exe prompt, then you enter this:
open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 <hostkey>"
Does it connect then?