How to Delete and List files with SFTP - genexus

is there a way to be able to interact with an SFTP server to perform these two operations:
Delete a file from the server
List the files that are in a folder on the server
Within the documentation I do not see these functionalities:
https://wiki.genexus.com/commwiki/servlet/wiki?44965,GeneXus+SFTP+Module
https://wiki.genexus.com/commwiki/servlet/wiki?44966,SFTP+Client
I am working with GX 17 U9, c#

Reading the GxWiki there is a warning about the use of this module.
I think you have two options:
Develop an external object with a standard library.
Use some command line tool like you could see here https://soic.iupui.edu/technology/kb/sftp/
If you want to do the second way, you can use the shell command:
https://wiki.genexus.com/commwiki/servlet/wiki?8502,Shell%20function

Related

How to upload a file to a server, that's not in the inventory?

Sometimes we need to upload logs of an application, that's distributed among multiple local Unix machines, to the vendor's server. The machines are all part of the same inventory, and can perform the archiving of the logs, and uploading the archives directly.
The server runs Unix and accepts only SCP and SFTP, so synchronize module (which uses rsync) will not work.
There exists a net_put-module, but that seems intended for uploads to special network appliances -- trying to use it, I get cryptic errors about ansible_network_os...
I can, of course, use the command module, but is not there something specifically targeted for SCP- and/or SFTP-servers?
No, there is no module for scp or sftp, and I don't really see that it would provide a lot of value. sftp and scp are straightforward to use with command, and the underlying commands don't really support the things you might want a module to do, like skipping an upload if the file on the remote wouldn't change.

Shell Script for file monitoring

I have 2 AWS EC2 LAMP servers and i want to replicate the data on one of the folders to others. I know I can try with EFS, but for some reason it is not a viable option at this moment. So, here is what I want to request for help:
Our Server A and Server B has same file structure but the files inside are mismatch. So, I want a script in Server A to look in, example, /var/www/html/../file/ folder and compare with /var/www/html/../file/ in Server B, and dump all new files from Server A to B.
Any help on how to write it?
Well, I used S3FS which is lot easier than breaking head over the script. It readily copies the files from one server to another.

With which FTP command can I find a specific file?

I want the FTP command to search for following:
1) Specific file name (for example - "abc.sql")
2) Specific content inside a file (inside .php/.js/.sql/.tpl files)
As there are many folders it will take some time to find that manually.
I am sure there is a command for 1, maybe also for 2, could someone please let me know what I need to enter to find that out. Can you please let me know?
The ftp protocol does not support either operation. You can read the definition of ftp here to see what is possible:
http://www.w3.org/Protocols/rfc959/
An ftp client could implement the search operation by recursively listing directory contents, but to search for contents inside files it would have to download all files.
It's possible that some ftp servers include support for these operations through site specific commands.

Is it possible to prevent overwriting files with ftp.exe?

I am referring to the Windows-native ftp.exe application. Out-of-the-box, it seems to overwrite files under any and all circumstances.
Is it possible to prevent overwriting files with ftp.exe? If this cannot be done with specific ftp.exe arguments, can it be done using a batch process to call ftp.exe?
I don't think there are any ftp arguments nor ftp command options to do what you want explicitly.
Using a batch process looks like the way to go (if you must stick to this ftp client).
You might have to do something like:
Ftp connect
List files (remote.txt)
Compare remote.txt with local.txt (files you want to upload)
Generate uploadables.txt (containing items from local.txt not in remote.txt)
Ftp connect again
Upload uploadables.txt
Sounds fun, but I better get back to work. :-)

Automated FTP to Windows servers

I need to set up some sort of infrastructure to automatically FTP some files from one remote server to another. The FTP transaction will occur on a scheduled basis. Both these servers are Windows boxes and the location of the files that need to be FTP'ed will depend on the current date (the folder they sit in will be named the current day's date).
I would really hate to have to write something like that from scratch, so are there tools/utilities/the likes out there?
Windows command line ftp will read input from a text file. For example:
ftp -ni < ftpscript.txt
Where these options are used:
-n - Suppresses auto-login upon initial connection.
-i - Turns off interactive prompting during multiple file transfers.
The ftpscript.txt would look something like this:
open ftp.mycompany.com
user someuser password
binary
get /somedir/myfile.dat
It should be reasonably straightforward to write a script that outputs an FTP script containing the correct file name.
You would think that this would be an easy task. It isn't.
The best tool I've found is SyncBack and I think there is a free/lite version available.
If you're in a Windows environment consider using PowerShell and the System.Net.WebClient .NET Framework class like this post. This is a download example, but the WebClient object also provides an UploadFile method.

Resources