Transfer a file from AS400 to another machine in the same network - db2

I am trying to export the data of a table on AS400 to another machine through iSeries commands but I am stacked in the middle of the process. I have a stored procedure in which I create the CSV file but after completion I need to transfer this file to another machine (which is of course connected to the AS400).
In the stored procedure, I used the CPYTOIMPF command to export table data to CSV and I wrote the file on the AS400 file system. I don't know if there is an option to write the file directly to another machine.
CALL QSYS2.QCMDEXC(
'CPYTOIMPF FROMFILE(LIBRARY/TABLE) TOSTMF('/QIBM/UserData/TestFolder/2.CSV') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)'
);
This step is completed and the file is written on that directory.
Now I need to transfer this file to a web server that is connected to AS400 without after the above command is completed.
How can I do that?

You can use FTP on IBM i. Here is a modified example from the IBM Knowledge Center
This is a CL program
PGM
OVRDBF FILE(INPUT) TOFILE(MYLIB/QCLSRC) MBR(FTPCMDS)
OVRDBF FILE(OUTPUT) TOFILE(MYLIB/QCLSRC) MBR(OUT)
FTP RMTSYS(SYSxxx)
ENDPGM
This program overrides the input of the FTP client to a script in MYLIB/QCLSRC member FTPCMDS, and the output of the FTP client to MYLIB/QCLSRC member OUT. The first line of the script must contain the userid and password for the remote location.
Here is a sample script from the same Knowledge Center reference:
ITSO ITSO <== This is the user id and password
CD ITSOLIB1
SYSCMD CHGCURLIB ITSOLIB2
GET QCLSRC.BATCHFTP QCLSRC.BATCHFTP (REPLACE
QUIT
This should not be used outside your network as the user id an password are sent in plain text. It also can be a security risk as production user id's and passwords must be stored in plain text in the source file.
In addition, Scott Klement has a presentation on how to use ssh, scp, and sftp on IBM i. This is quite a long thing, so you might want to read about it here.
A short summary is that scp might be the easiest way to go. but you will need to:
Make sure that OpenSSH option of the OS is installed.
Make sure your Windows server is set up as an ssh server.
Set up a digital key to use for the transfer. Private key goes on client side, and public key goes on server side.
Use scp fromfile user#host:tofile in Pase to transfer the file.

Related

How to store encrypted-dp{encrypted-password} using Windows odbcconf CONFIGSYSDSN or Set-OdbcDsn in PowerShell

When I edit a password in ODBC Data Source through a Windows "ODBC Data Source Administrator" dialog window, the password is stored in an encrypted manner like encrypted-dp{encrypted-password} in Windows registry.
When I edit the password using odbcconf CONFIGSYSDSN, it is stored as plain text in the registry.
Is there a way to store a data source password using programmatic way/script in the same way as the Windows ODBC dialog window does?
In this case, it was an external library, which was editing data source properties, encryption wasn't made as a part of the Windows process.
This lib was encrypting the password when changing the properties over the Data Source edit window - which was already a proprietary 3rd party window, coming from the lib.
We got an exposed "encrypt" method from the vendor, so we can also encrypt the password ourselves when using PowerShell.

Export a CSV file from AS400 to my pc through Cl program

I want to export a database file that is created through a query, from the AS400 machine to my pc in the form of a csv file.
Is there a way to create that connection of the AS400 and my pc through a cl program?
An idea of what I want to do can be derived from the following code:
CLRPFM DTABASENAME
RUNQRY QRY(QRYTEST1)
CHGVAR VAR(&PATH) VALUE('C:\TESTS')
CHGVAR VAR(&PATH1) VALUE('C:\TESTS')
CHGVAR VAR(&CMD) VALUE(%TRIM(&PATH) *CAT '/DTABASENAME.CSV' !> &PATH !> &PATH1)
STRPCO PCTA(*YES)
STRPCCMD PCCMD(&CMD) PAUSE(*YES)
where I somehow get my database file, give the path that I want it to be saved in, in my pc , and lastly run the pc command accordingly
Take a look at
Copy From Query File (CPYFRMQRYF)
Which will allow you to create a database physical file from the query.
You may also want to look at
Copy To Import File (CPYTOIMPF)
Which will copy data from a database physical file to an Integrated File System (IFS) stream file (such as .CSV); which are the type of files you'd find on a PC.
ex:
CPYTOIMPF FROMFILE(MYLIB/MYPF) TOSTMF('/home/myuser/DTABASENAME.CSV') RCDDLM(*CRLF) DTAFMT(*DLM) STRDLM(*DBLQUOTE) STRESCCHR(*STRDLM) RMVBLANK(*TRAILING)
FLDDLM(',')
However, there's no single command to transfer data to your PC. Well technically, I suppose that's not true. If you configure a (SMB or NFS) file share on your PC and configure the IBM SMB or NFS client; you could in fact CPYTOIMPF directly to that file share or use the Copy Object (CPY) command to copy from the IFS to the network share.
If your PC has an FTP server available, you could send the data via the IBM i's FTP client. Similarly, if you have a SSH server on your PC, OpenSSL is available via PASE and SFTP or SCP could be used. You could also email the file from the i.
Instead of trying to send the file to your PC from the i. An easier solution would be to kick off a process on the PC that runs the download. My preference would be a Access Client Solution (ACS) data transfer.
You configure and save (as a .dtfx file) the transfer
Then you can kick it off with a
STRPCCMD cmd('java -jar C:\ACS\acsbundle.jar /plugin=download C:\testacs.dtfx')
More detailed information can be found in the Automating ACS Data Transfer document
The ACS download compoent is SQL based, so you could probably remove the need to use Query/400 at all
Assuming that you have your IFS QNTC mapped to your network domain. You could use the command CPYTOIMPF to copy the data directly from an IBMI DB2 file to a network directory.
This sample would result in a CSV file.
CPYTOIMPF FROMFILE(file) TOSTMF('//QNTC/servername or ip/path/filename.csv') STMFCCSID(*PCASCII) RCDDLM(*CRLF) STRDLM(*NONE)
Use the FLDDLM(';') option in addition to make semicolon separated values, omit it to use comma as value separator.

How to give File access to Tableau server?

I have a .twb file created using the excel data source that is located in some network file path.
On publishing to server I get this error.
How to resolve this?
I need to provide some access for "Run as user" in my server machine,how could I do that ?
Ensure that when the workbook is created, a connection to the Excel file is created using the full UNC path
Ensure that the Tableau Server Run As user is able to access that file using the UNC path specified in the workbook. An easy way to test this would be to open Windows Explorer as the Run As user, then paste in the UNC path. If the Excel file opens, then you're good to go.
If you still have issues, test access to the file while logged into the Tableau server to make sure there is no firewall or port blocking access from that host. Often Excel isn't installed on servers for security reasons, so the test is not whether Excel opens the file, but whether you can view the contents from the server as the Run As User, even just using the type command at the console.
If you can't get your network access fixed, an alternative is to build and publish extracts to the server. There are multiple ways to accomplish that

In an SFTP session is it possible to copy one remote file to another location on same remote SFTP server?

Let say I have a file /home/user/dir1/file.txt on a remote SFTP server. I want to copy this file to lets say /home/user/dir2/file.txt, while I am in a sftp session (I have server which allows only sftp connections, but no ssh connections!) connected to this server?
Is it possible to do so? If yes, what is the command?
For example the following command would rename move a file from one directory to another on the remote server.
sftp> rename dir1/file.txt dir2/file.txt
I am looking for a command which would copy a file from one directory to another on the remote server, if one exists.
The work around is to download the file from first location and upload to the second location, but that is not an option when the file in question is a big one and one is working with a slow network connection!
Not sure what you mean by the "command". Are you referring to an SFTP protocol request? Or a command of some scriptable/command-line SFTP client (e.g. the OpenSSH sftp)?
The SFTP protocol on its own does not allow duplication of a remote file. Though there's an optional extension of the protocol named copy-file that serves the purpose.
Quoting the copy-file extension specification:
6. Copying Remote Files
byte SSH_FXP_EXTENDED
uint32 request-id
string "copy-file"
string source-file
string destination-file
bool overwrite-destination
This request copies a file from one location to another on the server. The server responds with SSH_FXP_STATUS.
Not many SFTP servers support the extension though. I know that ProFTPD mod_sftp and Bitvise WinSSHD do. The OpenSSH supports related copy-data only in very recent version 9.0.

scp command with alert message

I want to get the alert message for every execution of the scp command. If some one access my file using the scp command, that time I have to receive one mail. How can I achieve this. Please help me.
Unless you have administrative control of the server, what you ask is not possible -- Unix filesystems simply don't work that way. You can set your file permissions so that other users can't find or read your files, but there is no way for you, as an unprivileged user, to request email notification upon attempted or successful access attempts, via scp or any other method.
Are you on the server, or client side?
server side: Key-based ssh authentication has the ability to start custom commands when the user log into the system (can by bypassed if the user can change the authorized_keys file). There you can add a hook to send a mail on the login, or start a own sftp server with the desired logging enabled.
The right way to do that is to replace the scp program on the server by your own version (or by a wrapper).