Can I transfer a file from Windows to Unix using shell script, not WinSCP?

3

3

I would like to automate the WinSCP process, so I want to write a shell script which does the same as WinSCP.

I have tried using the SCP command, but it does not connect to my local machine. I have also seen PSCP, but I can’t install pscp.exe on my machine.

Dee

Posted 2016-10-06T14:16:20.283

Reputation: 39

2WinSCP is a complex program designed to deal with a complex set of underlying protocols. it will be a seriously non-trivial task to re-implement it, and it will almost certainly be less secure. First rule of cryptography is "never try to role your own", and if you are implementing cryptographic processes in your application, that this must be done with significant care. Additionally WinSCP ships libraries for application integration and scripting. I use WinSCP dlls in my .Net programs regularly. – Frank Thomas – 2016-10-06T14:25:21.290

Shell script on Windows? Or do you mean batch file? Anyway, do you mean it seriously, to implement a cryptography in a shell script? Or are you looking for a plain unsecure FTP? – Martin Prikryl – 2016-10-06T14:56:06.813

You can automate Winscp. What reason precludes using Winscp? What protocol do you need to use? Why do you even mention bash if you are sending from Windows. – jiggunjer – 2016-10-06T16:28:18.350

What version OS are you using? – voices – 2016-10-07T22:02:16.643

Answers

2

Install Putty, then use:

c:\progra~1\putty\pscp.exe c:\local_path\to\files.*  user@host:/destination/directory

You can use keys (generate a pair, and put only the public key (exported in the right format!) into the destination user's .ssh/authorized_keys file ) to make this automatic (ie, without need for you to interactively enter a password each time) and secure. To use your key with pscp, just add the option -i \path\to\PRIVATEkey, before source and destination.

Olivier Dulac

Posted 2016-10-06T14:16:20.283

Reputation: 818

Yes , I was doing the same . I created private and public keys and I was able to log in with the keys . I am good here . After that I am trying to use scp command to move files from local system to unix , but its not working. – Dee – 2016-10-06T19:09:32.813

@Dee: the script is run from windows... if you want to run in from the unix machine, then use scp there, generate a key there, and have a ssh server on your windows (ex: one exit in cygwin), and firewall shoukd allow port tcp22... – Olivier Dulac – 2016-10-06T19:22:14.000

and if run from windows, the bat file should add the usage of the key : c:\progra~1\putty\pscp.exe -i \path\to\privatekey Sourcefiles user@host:/destinationdir/ – Olivier Dulac – 2016-10-06T19:24:40.130

1

I can recommend the DOS Batch FTP Scripts page.

I needed to do this at my work (it was a little competition between sysadmins), and this helped me a lot. You also can use FileZilla with CommandLine or something else which provides a full FTP support.

CentrixDE

Posted 2016-10-06T14:16:20.283

Reputation: 413

Hello, I tried using FTP , I saved a file on desktop with .bat extension and was trying to connect to my unix server , it says not connected , Can you please let me know what is wrong in my code . – Dee – 2016-10-10T18:27:20.527

1@echo off cd C:\filestobeFTP'ed echo open unixserver.com> C:\temp.txt echo user name XXXXXXX>> C:\temp.txt echo pwd>> C:\temp.txt for /r %%i in (*) do echo put %%i>> C:\temp.txt echo quit>> C:\temp.txt ftp -n -s:C:\temp.txt cd .. – Dee – 2016-10-10T18:31:03.570

1

If you're using Windows 10 with the Anniversary Update, you can install the Linux subsystem for Windows and use regular scp.

Charles Burge

Posted 2016-10-06T14:16:20.283

Reputation: 1 792

0

you can use VBScript and a version of XMLHTTP. The following sub downloads instead of uploads, but it can give you a start:

Sub wGet(strURL, strLocalFile)
'
' Example Usage
' wGet URLtofile, LocalFileSpec
'
  Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
  With objXMLHTTP
    .Open "GET", strURL, False
    .Send
    If .Status = 200 Then
        Set objStream = CreateObject("ADODB.Stream")
        With objStream
          .Open
          .Type = 1
          .Write objXMLHTTP.responseBody
          .SaveToFile strLocalFile, 2
          .Close
        End With
    Else 
      varToUser = MsgBox("Web server returned an error", _
                  vbInformation, "ASU Portable Environment Setup")
      Wscript.Quit
    End If
  End With
  Set objXMLHTTP = nothing
End Sub

John Bonifas

Posted 2016-10-06T14:16:20.283

Reputation: 1