How to use FTP using Progress 4GL? - progress-4gl

Is there any way to send files from a local folder to an FTP folder using Progress?

If you're running windows, then WinSCP is a good solution:
http://winscp.net/eng/index.php

The "classic" way to do this is to send the commands that you would use if you were doing this manually to the built-in FTP command.
If you know that you want to send a file called "myfile.txt" to the server at 192.168.0.1 you might code:
define variable IPAddr as character no-undo.
define variable fileName as character no-undo.
IPAddr = "192.168.0.1".
fileName = "myfile.txt".
output through value( "ftp -v -i -A" + IPAddr ).
put unformatted "put " + fileName skip.
put unformatted "bye " skip.
output close.
Obviously you can wrap that into a function and expand it to do more than a simple FTP PUT command (you might need to login...)
FTP is an insecure protocol and a PITA to work with. If you have any influence over such things you really ought to try to use a better protocol. SCP is much easier to use and has much better security.

DEFINE VARIABLE cFtpCommand AS CHARACTER NO-UNDO.
cFtpCommand = "your FTP COMMAND".
OS-COMMAND SILENT NO-CONSOLE VALUE(cFtpCommand).

Related

kdb string path miss quotation mark

I would like to join strings for file name and shell script so I can run the command line in kdb for ftp transfer.
But there are quotations in quotation marks. not sure how to add / in there.
This is the code I have:
host:"abc.com";
usr:"def";
path:"get /home/eddie/abc.csv /home/terry/";
cmd:" " sv ("/home/kdb/eddie/ftp.sh";host;usr;path);
system cmd;
So the path will not have quotation mark and will be running error. How can I solve this problem?
You can escape quotes with \ e.g. "\"Matt\"" but I don't think that's your issue. It looks like you are attempting to use get in the system command. This is a kdb keyword and your OS will not recognise it. You should just be passing the location of the csv to your ftp script.
Edit:
You may also need sh in the system command.
cat test.sh
echo $1
system "test.sh hello"
sh: ./test.sh: Permission denied
'os
system "sh test.sh hello"
"hello"
Assuming that you simply want quotes within a string, it may just be as simple as using .Q.s1 aka -3!, see https://code.kx.com/q/ref/dotq/#qs1-string-representation
q)" " sv ("/home/kdb/eddie/ftp.sh";host;usr;.Q.s1 path)
"/home/kdb/eddie/ftp.sh abc.com def \"get /home/eddie/abc.csv /home/terry/\""
q)" " sv ("/home/kdb/eddie/ftp.sh";host;usr;-3!path)
"/home/kdb/eddie/ftp.sh abc.com def \"get /home/eddie/abc.csv /home/terry/\""

How to append binary blob to PowerShell script to be ignored as script text?

A Unix shell (bash, dash tried) interprets a script line by line. This allows to attach some binary data to the end of the script. My particular example is a Jar file that can be automatically unzipped or run from that very script.
I wonder if this is somehow possible with PowerShell too. I tried and got errors which indicate that the PowerShell seems to parse the whole file first before starting to run it.
Is there a way to mark the rest of a file such that the PowerShell does not try to interpret it but just ignores it?
Since my specific use case is that I want to make a Jar file executable, solutions relying on base64 encoding the binary blob do not work.
To be even more explicit: the script will basically run
java -jar $MyInvocation.MyCommand.Definition #Args
such that java shall use the file as a jar file.
What makes you think a solution using base64 encoding wouldn't work? Convert the file to a base64 string like this:
$bytes = [IO.File]::ReadAllBytes('C:\path\to\your.jar')
[Convert]::ToBase64String($bytes)
and put the string into your script as a variable:
$jarData = 'UEsDBBQAAAAA...'
If you prefer a multiline base64 string you can wrap it like this:
[Convert]::ToBase64String($bytes) -replace '(.{80})', "`$1`n"
and put it into the script like this:
$jarData = #'
UEsDBBQAAAAA...
...
'#
Have your script decode the data and save it back to a file upon execution:
$bytes = [Convert]::FromBase64String($jarData)
[IO.File]::WriteAllBytes("$env:TEMP\your.jar", $bytes)
To my knowledge this is the only way to embed binary data in PowerShell scripts.

file transfer using ssh sftpg3

I am writing a Perl script to do a secure file transfer using SSH sftpg3.exe
But I am having issue to accessing the source file.
the script able to pick the file from C:\xx\t.txt while running it from the directory
It is not showing error C:\Program is not a valid command.
my $sftpPath="C:\\Program Files\\client";
my $srcPath="C:\\xx\\test.txt";
my $trgCommand=$sftpPath." -D $srcPath user#host:/tmp/";
my $result=system("$trgCommand");
while running this script from C:\ directory it is running without error but I can not see the file in destination server.
Could you please help me sort out this file path issue ?
I want to run it from O:\ and it will pick the target file and sftpg3.exe from C:\ drive and do the file transfer (in ASCII mode) successfully.
try the below code
my $cmd="sftpg3.exe " . "$src_path user#host:";
system("C:\\Program Files\\Client\");
system($cmd);
Thanks.
You might have interpolation of #host in your third line because you are using double quotes (""). Do you have use strict and use warnings turned on? There might also be an issue with the space () in the path.
use strict;
use warnings;
use feature 'say';
my $sftp_path = q{"C:\Program Files\Client\sftpg3.exe"};
my $src_path = 'C:\xx\test.txt';
my $result = system( $sftp_path, '-D', $src_path, 'user#host:/tmp/' );
say $result;
Let's look at what I did.
When you tab-complete a path like C:\Program Files\foo in Windows cmd, it usually wraps them in double quotes if there is a space inside the path. So we use the q operator, which is equivalent to single quotes, and put double quotes inside. That also gives us the benefit that we don't have to escape the backslash \. Also see quote-like operators in perlop.
Same goes for the source path.
system allows you to pass all the arguments to the program you want to run as arguments to itself and will take care of the quoting
The double quote in "user#host:" will try to expand #host as an array. That doesn't work, because it's not defined. So there's a warning that you probably didn't see because you did not use strict and use warnings. Instead of the double quotes, use single quotes.
I used $sftp_path instead of $sftpPath because there is a convention in Perl to use underscores and no capital letters. We like camels, but not in our variable names. :)

Passing Parameters/Argument to FTP filename from DOS

I am calling a FTP file from DOS, which holds ftp set of commands as follows:
ftp -s:ftpcmd1.txt
Now, the change requirement says, file is to be called multiple times with different file paths.
so, I need to write above statement, each time passing new file path as argument with FTP filename and writing something like "%1" in command inside ftp-file. Please help me with same. How do I do it.
Thanks.
I dont know if we can pass parameter to ftp script (atleast in DOS). But in the above case dynamically written out ftp script file would help. Small bat file which would do that is like below.
echo "user username pwd">ftpcmd1.txt
echo "bin">>ftpcmd1.txt
echo "put %1">>ftpcmd1.txt
echo "bye">>ftpcmd1.txt
ftp -n -i -v servername<ftpcmd1.txt
If you call this bat file with any file name as the first command line argument, it would transfer the file to target servername. Hope this is what you are looking for.

How can I write to the parallel port from the Windows Command line?

How can I write to parallel port through Windows XP command line?
Looking at your reply to Zoredache, your real problem is not output to the parallel port, that's trivial.
Your real problem is how to get a 0xff character on stdout. This is possible with a trivial .com executable which invokes the relevant soft interrupt, but to be honest it's probably easier to create a file with that single 0xff character in it and then just copy that to the printer:
> copy /b data.bin lpt1
Note the /b flag which tells copy that the file is a binary file.
Back in the DOS days we would frequently use a command like type filename.txt > lpt1 to print our text files.