Topic "How to Put the date & time format files into SFTP server?"

Author Message
limitha
[View user's profile]

Joined: 2013-03-06
Posts: 8
I am doing SFTP task in SSIS.
i am using the following script.

option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# open sftp://MPesa:OXIVMP@123@Mysftpserver:22
# Connect
open sftp://MPesa:OXIVMP@123@MySftpserver:22
# Change remote directory
cd /MPesa/
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
put D:\SCW_Reports\Oxigen.txt
# Disconnect
close
exit

The above code working fine.
How to put the Oxigen_03052013.txt format files.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
Best would be to use WinSCP .NET assembly.
https://winscp.net/eng/docs/library

Or follow this guide:
https://winscp.net/eng/docs/script_download_timestamped_filename
_________________
Martin Prikryl
limitha
[View user's profile]

Joined: 2013-03-06
Posts: 8
// Local path to download to (keep trailing slash)
var LOCALPATH = "\\D:\SCW_Reports";
// Remote path to download from (keep trailing slash)
var REMOTEPATH = "/cd/MPesa";
// File to download
var FILE = "winscp421.exe";
// Session to connect to
var SESSION = "MPesa@OXIVMP@123@127.10.16.223";
// Path to winscp.com
var WINSCP = "C:\Program Files (x86)\WinSCP\WinSCP.com";

// helper function to pad zeroes to the left of number
function pad(n, len)
{
var s = n.toString();
while (s.length < len)
{
s = '0' + s;
}
return s;
}

var date = new Date();

// format timestamp
var stamp =
pad(date.getFullYear(), 4) +
pad(date.getMonth(), 2) +
pad(date.getDate(), 2) ;

var shell = WScript.CreateObject("WScript.Shell");

// run winscp to download the file into timestamped-filename
exec = shell.Exec("\"" + WINSCP + "\"");
exec.StdIn.Write(
"option batch abort\n" +
"open \"" + SESSION + "\"\n" +
"Put \"" + REMOTEPATH + FILE + "\" \"" + LOCALPATH + FILE + "." + stamp + "\"\n" +
"exit\n");

// wait until the script finishes
while (exec.Status == 0)
{
WScript.Sleep(100);
WScript.Echo(exec.StdOut.ReadAll());
}

I ran the above scrpt , output was not showing.
limitha
[View user's profile]

Joined: 2013-03-06
Posts: 8
Error Code: 0 Error Source= Microsoft JScript runtime error Error Description: 'WScript' is undefined Error on Line 30.[/size]


// Local path to download to (keep trailing slash)
var LOCALPATH = "\\D:\SCW_Reports";
// Remote path to download from (keep trailing slash)
var REMOTEPATH = "/cd/MPesa";
// File to download
var FILE = "winscp421.exe";
// Session to connect to
var SESSION = "MPesa@OXIVMP@123@127.10.16.223";
// Path to winscp.com
var WINSCP = "C:\Program Files (x86)\WinSCP\WinSCP.com";

// helper function to pad zeroes to the left of number
function pad(n, len)
{
var s = n.toString();
while (s.length < len)
{
s = '0' + s;
}
return s;
}

var date = new Date();

// format timestamp
var stamp =
pad(date.getFullYear(), 4) +
pad(date.getMonth(), 2) +
pad(date.getDate(), 2) ;

var shell = WScript.CreateObject("WScript.Shell");

// run winscp to download the file into timestamped-filename
exec = shell.Exec("\"" + WINSCP + "\"");
exec.StdIn.Write(
"option batch abort\n" +
"open \"" + SESSION + "\"\n" +
"Put \"" + REMOTEPATH + FILE + "\" \"" + LOCALPATH + FILE + "." + stamp + "\"\n" +
"exit\n");

// wait until the script finishes
while (exec.Status == 0)
{
WScript.Sleep(100);
WScript.Echo(exec.StdOut.ReadAll());
}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
limitha wrote:
Error Code: 0 Error Source= Microsoft JScript runtime error Error Description: 'WScript' is undefined Error on Line 30.

How are you running the script?
_________________
Martin Prikryl
limitha
[View user's profile]

Joined: 2013-03-06
Posts: 8
I ran the script through SQL agent.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
limitha wrote:
I ran the script through SQL agent.

Ok, can you be more specific? Like command-line you used. Do you use wscript or cscript or somethine else?
_________________
Martin Prikryl
cdmiss
[View user's profile]

Joined: 2013-03-22
Posts: 1
Hi

I am searching the location/path/file where private keys are stored in sFTP. I mean the private key of encrypted packages.
Does anyone know how i can find some kind of information like this

Thanks a lot
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License