Apache commons net FTPClient storeFile() creating file with the username prefixed - mainframe

Happy New Year! :)
So, I'm using the Apache Commons FTPClient for the first time to FTP a file to the Mainframes FTP server. I have the code below to setup required configurations and eventually FTP the file using storeFile() which seems to work except one small problem below.
ftpClient.login(username, password);
System.out.println(ftpClient.getReplyString());
File blankFile = new File("./src/main/resources/BLANK.DAT");
System.out.println("File exists: "+ blankFile.exists());
InputStream inputStream = new FileInputStream(blankFile);
ftpClient.sendSiteCommand("sbdataconn=****.****.*****"); --Hidden from post
System.out.println(ftpClient.getReplyString());
ftpClient.sendCommand(FTPCmd.PWD);
System.out.println(ftpClient.getReplyString());
ftpClient.sendSiteCommand("lrecl=80 blksize=3120 recfm=FB");
System.out.println(ftpClient.getReplyString());
ftpClient.sendSiteCommand("pri=5 sec=15");
System.out.println(ftpClient.getReplyString());
ftpClient.storeFile("Destination.File.Name",inputStream);
System.out.println(ftpClient.getReplyString());
The corresponding console output logs say:
Connected to ****ftp.****.com.
220-FTPD1 IBM FTP CS V2R3 at *****, 06:46:21 on 2021-01-05.
220 Connection will close if idle for more than 15 minutes.
230 USERNAME is logged on. Working directory is "USERNAME.".
File exists: true
200 SITE command was accepted
257 "'USERNAME.'" is working directory.
200 SITE command was accepted
200 SITE command was accepted
250 Transfer completed successfully.
The Mainframes team confirms that they are seeing the file but the file is named as 'USERNAME.Destination.File.Name', but we need the file to be named as 'Destination.File.Name' to kick off the next step in processing. Am I missing something in my configs? Or is this an expected behaviour when FTPing to Mainframes using Apache Commons. How do I go further from here? Any help is appreciated. Thanks!

Well, it appears the filename in the storeFile() method of FTPClient had to be enclosed within single quotes('') to have the file created with exactly that name. So, the solve was to simply replace
ftpClient.storeFile("Destination.File.Name",inputStream);
with
ftpClient.storeFile("'Destination.File.Name'",inputStream);
and it worked as expected.
Thanks and have a wonderful 2021.

Related

How to capture the Notes Data directory specified in notes.ini?

I need to get the value for the Notes data directory. I need it for a scheduled agent I am going to run. The program directory and data directory are on separate drives.
I thought the following code would work but I am not getting a return value.
String console = session.sendConsoleCommand(servername, "show config Directory");
//Code runs but the following line does not display anything
System.out.println(" Here is console value: " + console);
There are not any permission or other errors. What am I missing?
V/R,
Kev
Why use this obscure construct? Do you need the directory of ANOTHER server?
If you need it from the server where the agent runs then just use
String directory = session.getEnvironmentString("Directory", true)

Maximum execution time of 300 seconds exceeded in

I know this subject has like ... many duplcates here and there, but trust me I've spent time fetching these posts and my question remains answerless.
I'm running a PHP script on a Debian Linux / Nginx / PHP-FPM / APC / I think that's all.
I'm executing the script from my SSH terminal (CLI) like : > php plzrunthisFscript.php &
It used to work flawlessly but now, it returns this famous error.
What I've tried ALREADY and it failed (I mean it didn't change anything) :
Check what PHP.INI was used with a phpinfo(); inside my script (it's /etc/php5/cli/php.ini)
maximum_execution time is hardcoded to 0 (means no limit) for CLI if I'm not mistaken.
Tried to add at begining of my script : set_time_limit(0);
Tried to add : ini_set('max_execution_time', -1);
Tried to execute my php command with parameter -d max_execution_time=0
Tried to execute from a web interface (served by Nginx)
Tried to execute from another web interface (SErver by Apache2 this time) gives same error on page.
tried to configure max_execution_time 15 in /etc/php5/cli/php.ini to check if the php.ini that is supposed to be used (because phpinfo() inside my script is ignored or not : it's ignored
Everytime, it brings this error, and sometimes even after more than 300 seconds I think, which is really confusing.
If someone has any idea on how to fix this, or has some things I can try, please advise.
Thank you for your time.
God I finaly solved it!
I think that could be considered as a Magento Bug in a way.
Here is how to reproduce this :
You have Magento (My version is CE 1.7) running with APACHE 2.
One day, you decide to get rid of Apache and try to adopt Nginx.
You configure everything and it's working great, but you end up with this error one day, trying to rebuild your indexes as you often do.
Thing is, when you run (for example) : php indexer.php --reindex catalog_url &
This script includes another one called abstract.php which contains this awesome function :
protected function _applyPhpVariables()
This function will look for a .htaccess in your Magento root directory, then parse every single configuration parameters, and will execute the index script with these parameters.
How clever ...
Anyway, to solve this you just need to (delete / rename / burn) this .htaccess file, and then everything will go back to normal.
Thanks for your help everyone.

PHP fopen "failed to open stream: resource temporarily unavailable"

EDIT: Austin below in the comments resolved my issue. How do I close the question since that is the answer?
I have the following simple code to open/write to a query file on my server. I've checked permissions and even set +rw for all users on the query file, yet I still get the error
failed to open stream: resource temporarily unavailable
in my apache error log.
I'm not really sure what I can do to alleviate this issue, thoughts?
<?php
// filepaths
$queryFile = '../query/query.txt';
// get query
$query = $_GET['searchBox'];
// open and write query to query file
$fh = fopen($queryFile, 'X') or die("Can't open file");
fwrite($fh, $query);
fclose($fh);
It could only be one of a few things:
The PHP process is out of memory, file handles, or similar
The PHP environment's own limitations are exceeded somehow
The file itself has some limitation, such as a SELinux (Security Enhanced Linux) restriction.
To determine which it is, try opening the file outside PHP. Temporarily alter the script to open a different file. Look at what else the script does to validate whether it could possibly be running out of file handles, etc.
What does is_file($queryFile) and is_writable($queryFile) reveal? Maybe you are not in the correct working directory?
The parameter 'X' should be lowercase.

FTP.retrbinary fails

I'm a complete Python novice, so I apologize if the solution to my problem seems obvious. I'm having difficulty with some relatively simple code that I've written. I've scanned several related questions that have already been posted, but I don't see where my code differs in any meaningful way from the solutions suggested.
I'm trying to write a program that will:
Establish a ftp connection to a remote server.
Change the working directory on the ftp server.
Retrieve a list of files in the working directory from the ftp server.
Find a file ending with a specific suffix from the retrieved list of files.
Retrieve the found file to a temporary directory (created by tempfile.mkdtemp()) on the user's local file system.
Steps 1 through 4 are working as expected. Sadly, the last step is falling into my except clause.
Can anyone make a suggestion regarding what might be wrong with the following line of code?
ftp.retrbinary('RETR ' + file, open(opsys.path.join(localTempDir, fileName)).write)
Your suggestions are greatly appreciated. Thanks, in advance.
Possible problems:
- type(file) = incorrect value
- opsys.path.join(localTempDir, fileName) = incorrect value #nonexistent file
Thats all what comes to mind looking on presented line of code =)

SAP, how to checkIn document files?

I want to create a new document in SAP. Additional I have some files which belongs to this document, these files I want to upload to the SAP knwolegde base.
I'm using BAPI_DOCUMENT_CREATE2 to create or BAPI_DOCUMENT_CHECKIN2 to add files to a document info data. Every thing works fine, except file upload or checkin.
I'm using the DOCUMENTFILES table. I add a row for each file, currently I set only three fields:
row["STORAGECATEGORY"] = "DMS_C1_ST";
row["DOCFILE"] = "c:\temp\bom.pdf";
row["WASAPPLICATION"] = "PDF";
BAPI erro message:
"Error while checking in and storing c:/temp/bom.pdf"
I set the parameter
PF_FTP_DEST = "SAPFTPA";
PF_HTTP_DEST = "SAPHTTPA";
I have looked in the log data (slg1). I found following entry:
ERRMSG: Error in opening file "..." for reading (No such file or directrory)
V1: SCMS_DOC_CREATE_FILES
V2: 13
It would be nice if anybody has an idea and could bring some light in this issue.
Thanks in advance
Thomas
Remember that BAPIS run inside the application server and are not allowed to make any assumptions about the client side. This also means that they can't call back to the SAP GUI and upload a file from there. C:\temp\bom.pdf has to be a file on the application server, not your local machine!
Have you considered using
row["DOCFILE"] = "bom.pdf";
row["DOCPATH"] = "c:\temp\";
Let me know how it goes, or if you have already done with it then please paste your solution.

Resources