Suggestions for an SFTP process

Started by MW4, April 17, 2014, 10:39:16 AM

Previous topic - Next topic

MW4

I have a process that I need to set up that will do the following:
  1.  Connect with an SFTP server
  2.  Download some specifically named files to a local folder
  3.  Decrypt all of the files in that folder.
  4.  Them move them to the specific folders that they will need to reside in for use.

We have used Cleopatra on a singular file basis and the connect and decrypt works fine, we just need to automate it into a scheduler job.
Any help in pointing me in the right direction would be fantastic.
If there is a better solution than Cleopatra, I'm all ears.

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

MW4

ok, I hit a snag with the script.

ObjectClrOption ( 'use', 'WinSCP, Version=1.1.5.4214, Culture=neutral' )

that is the version of the dot.net dll that I downloaded today



Deana

You might want to make sure your are using the correct assembly directory path in the APPBASE statement, before calling the USE. Also click on the More Error Info button and post the resulting extended error information.
Deana F.
Technical Support
Wilson WindowWare Inc.

MW4


MW4

Currently I can pull the files manually until I can get the WinSCP part working.

So...

How about the Decrypt part, what is suggested for that?

Deana

Did you check the AppBase folder is correctly pointing the WinSCP directory?

What is the name of the dll in the WinSCP directory?



Deana F.
Technical Support
Wilson WindowWare Inc.

MW4


Deana

The dll name is WinSCPnet.dll therefore your script should read:

Code (winbatch) Select
ObjectClrOption ( 'use', 'WinSCPnet, Version=1.1.5.4214, Culture=neutral' )
Deana F.
Technical Support
Wilson WindowWare Inc.

richardh

I will definitely be using this example for my needs.
Thanks Deana  :)

MW4

Getting these two errors in the attachments...
looks like WinSCPnet is not coming through (from trace below)

ObjectClrOption ( 'use', 'WinSCPnet, Version=1.1.5.4214, Culture=neutral' )

mscorlib=Could not load file or assembly 'WinSCP, Version=1.1.5.4214, Culture=neutral' or one of its dependencies. The module was expected to contain an assembly manifest.


td

The "mscorlib=Could..." error is just a legacy error living on in the ini file.  The second error is relevant and indicates that you are either using an invalid or incorrectly formated thumb print. You need to verify that you have the correct hash and that it is in the format expected by the SshHostKeyFingerprint method.  Also, you need to check that all the other parameter option you are assigning are correct as any of these could might be the source of the error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

I had mis matched Program versions and the .net dll
Fixed that.
I also had a bad path...fixed and works!!!!!


Woo HOO!!!

Thank You  Deana!!


MW4

Now as a finishing piece...

what's the command to delete that file from the FTP server after a download?


second finishing piece....

Files are in that folder as this:
/outbound/NNA2FAIR_INVOC.2014_07_10_0132.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0145.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0156.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0159.TXT.PGP

I need to pull many files that start with /outbound/NNA2FAIR_INVOC <WILDCARD>
and save them to my local dir using the whole filename.

The folder contains files that are not mine so I don't want to sync the entire directory.

Using the code like it is, how would you accomplish that?



td

The online documentation for the WinSCP assembly is quit good.  I recommend you check it out.  It clearly states that the 'GetFiles' method accepts wildcards so if your files can be identified by name, you could construct a wildcard file name the matches the files you want to retrieve.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

I just looked through that and it works quite well.

I got the wildcard and am about to test the delete.

Thanks again for the help

MW4

bFalse = ObjectType( 'BOOL', 1 )

1 sets delete



transferResult = objSession.GetFiles( '/outbound/NNA2FAIR*', 'c:\tempy\', bFalse, objTransferOptions) 

* = standard wildcard

MW4

One further question on this topic...

What is the easiest way to query up the "oldest" file and then just download that one... IE:

from these files in the directory
/outbound/NNA2FAIR_INVOC.2014_07_10_0132.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0145.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0156.TXT.PGP
/outbound/NNA2FAIR_INVOC.2014_07_10_0159.TXT.PGP


/outbound/NNA2FAIR_INVOC.2014_07_10_0132.TXT.PGP  would be the oldest

td

If you can assume that the oldest last write time for a file also means that it is the oldest file then the 'GetFileInfo' method of the Session object looks interesting.

The method can be found here:

http://winscp.net/eng/docs/library_session_getfileinfo#parameters

and the method's return class here:

http://winscp.net/eng/docs/library_remotefileinfo

The 'ListDirectory' method might be an even better choice:

http://winscp.net/eng/docs/library_session_listdirectory

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade