Upload Files to Mainframes from VB.net - vb.net

I am trying to upload a file from my pc to mainframes. I am trying to upload it using Chilkat FTP2. Below is the code.
The file I am trying to upload is 2009102600000
Dim ftp As New Chilkat.Ftp2()
Dim success As Boolean
' Any string unlocks the component for the 1st 30-days.'
success = ftp.UnlockComponent("Anything for 30-day trial")
If (success <> true) Then
MsgBox(ftp.LastErrorText)
Exit Sub
End If
ftp.Hostname = "www.myside.com"
ftp.Username = "****"
ftp.Password = "****"
' The default data transfer mode is "Active" as opposed to "Passive".'
' Change it to Passive by setting the Passive property:'
ftp.Passive = true
' Connect and login to the FTP server.'
success = ftp.Connect()
If (success <> true) Then
MsgBox(ftp.LastErrorText)
Exit Sub
End If
' Change to the remote directory where the file will be uploaded.'
success = ftp.ChangeRemoteDir("ABC.SITEUPLOAD.UPLOAD")
If (success <> true) Then
MsgBox(ftp.LastErrorText)
Exit Sub
End If
' Upload a file.'
Dim localFilename As String
localFilename = "c:\2009102600000"
Dim remoteFilename As String
remoteFilename = "2009102600000"
success = ftp.PutFile(localFilename,remoteFilename)
If (success <> true) Then
MsgBox(ftp.LastErrorText)
Exit Sub
End If
ftp.Disconnect()
MsgBox("File Uploaded!")
The error I am getting is dataset not found use MVS dsn name or something like that.
I would really appreciate if you can help me out with this one please.

I'm not at all sure you can treat data set prefixes as directories. When I'm doing uploads to the mainframe with ftp, I always just specify the full target name. I would get rid of the
ftp.ChangeRemoteDir("ABC.SITEUPLOAD.UPLOAD")
section altogether and just change:
remoteFilename = "2009102600000"
to:
remoteFilename = "'ABC.SITEUPLOAD.UPLOAD.2009102600000'"
if it's a sequesntial data set, or:
remoteFilename = "'ABC.SITEUPLOAD.UPLOAD(2009102600000)'"
if it's a member (in which case the data set will have to exist first).
It would also help if you changed the MsgBox statements so that they included an indication as to what is actually causing the error. Something along the lines of:
MsgBox("Connect error: " & ftp.LastErrorText)
MsgBox("ChangeRemoteDir error: " & ftp.LastErrorText)
MsgBox("PutFile error: " & ftp.LastErrorText)
instead of the generic:
MsgBox(ftp.LastErrorText)
One other point: you'll notice I've put single quotes around the targets above. That's because z/OS has a habit of (sometimes) prefixing your login name to members. It may be that:
put xyz.txt upload(xyz)
is actually trying to put it into yourname.upload(xyz). Quoting it will prevent that.
Update: You know, I just noticed something that totally escaped me the first time I read this question. The error message spells it out plainly.
Data set name segments and member names within partitioned data sets are limited to 8 characters. Hence your 'ABC.SITEUPLOAD.UPLOAD(2009102600000)' is invalid on two counts, the SITEUPLOAD and the 2009102600000. Try shortening the names and re-transferring.
Here's the proof:
C:\Documents and Settings\Pax> ftp bigiron
Connected to bigiron.box.com.
220-FTPD1 IBM FTP CS V1R9 at BIGIRON.BOX.COM, 02:15:23 on 2009-11-06.
220 Connection will close if idle for more than 5 minutes.
User (bigiron.box.com:(none)): pax
331 Send password please.
Password:
230 PAX is logged on. Working directory is "PAX.".
ftp> put test.txt 'pax.siteupload'
200 Port request OK.
501 Invalid data set name "'pax.siteupload'". Use MVS Dsname conventions.
ftp> put test.txt 'pax.siteupld'
200 Port request OK.
125 Storing data set PAX.SITEUPLD
250 Transfer completed successfully.
ftp: 177 bytes sent in 0.00Seconds 177000.00Kbytes/sec.
ftp> put test.txt 'pax.jcl(abcdefghi)'
200 Port request OK.
501 Invalid data set name "'pax.jcl(abcdefghi)'". Use MVS Dsname conventions.
ftp> put test.txt 'pax.jcl(abcdefgh)'
200 Port request OK.
125 Storing data set PAX.JCL(ABCDEFGH)
250 Transfer completed successfully.
ftp: 177 bytes sent in 0.00Seconds 177000.00Kbytes/sec.
ftp> bye
221 Quit command received. Goodbye.

Are you sure you don't need to store it as a generational dataset from the root directory? Like this:
'ABC.SITEUPLOAD.UPLOAD.2009102600000(+1)'

Related

QB64 Open Com port causes data read error

There seems to be a fundamental problem with QB64 Open Com statement at least with my compiler. When I open the com port with OPEN "Com3: 9600,n,8,1,ds0,cs0,rs" FOR RANDOM AS #1 while knowing that there is data in the buffer and print EOF, LOC, LOF. It shows EOF=0 OK fine but LOC and LOF both show 0. If you then exercise a GET statement you get a "bad record length" because LOF=0. If I use OPEN FOR INPUT then I immediately get EOF=-1, LOF and LOC=0. If I then use INPUT# I get an input past end of file error because EOF was already -1.
I know that the buffer contains" Voltage = 1.2* "(no quotes) If I say continue upon the input past end of file error I actually get Part of the message.
Is there a fix for this com port problem?
If you test the com port you will find Windows nicely blocks those ports:
REM test com port keyboard i/o
OPEN "COM3:9600,N,8,1,BIN,CS0,DS0" FOR RANDOM AS #1
DO
IF LOC(1) THEN
GET 1, , x
PRINT CHR$(x);
END IF
x$ = INKEY$
IF LEN(x$) THEN
IF x$ = CHR$(27) THEN END
x = ASC(x$)
PUT 1, , x
END IF
LOOP
END

displaying all cmd.exe text to textbox

I've search high and low looking for a way to display all text from FTP.exe to a richtextbox. so far i've only been able to do is display the output code. the idea is to run the test and display and capture to a file which hasn't been a problem except i can't seem to display all text as you would see it in Command.Hoping to see all text when done. Please Help!!
Here is he code:
Private Sub Rectangle1_Click(sender As Object, e As EventArgs) Handles Rectangle1.Click
Dim p As New Process()
With p
.StartInfo.Arguments = " -s:c:\dsl\ftptest\speed1.txt 65.40.220.20"
.StartInfo.CreateNoWindow = True
.StartInfo.FileName = "ftp"
.StartInfo.RedirectStandardError = True
.StartInfo.RedirectStandardOutput = True
.StartInfo.UseShellExecute = False
.Start()
Dim StErr As StreamReader = .StandardError
Dim StOut As StreamReader = .StandardOutput
While (Not StOut.EndOfStream)
Me.RichTextBox1.AppendText(String.Format("{0}", StOut.ReadLine() & vbCrLf))
End While
.WaitForExit()
End With
End Sub
End Class
Here is the output from the code:
User (65.40.220.20:(none)): Hash mark printing On ftp: (2048 bytes/hash mark) .
hash
get test.1meg
#
cd upload
put test.1meg
#
close
bye
Here is What I'm looking for:
C:\DSL\FTPTEST>call FTP -s:c:\dsl\FTPtest\speed1.txt 65.40.220.20
Connected to 65.40.220.20.
220-
This server is provided as a EMBARQ Speedtest server for DSL customers only.
Any other use is prohibited.
You may login using anonymous ftp and download the test files to determine your speed.
You may upload the same files to the upload directory to test your upload speed.
You may only upload the files that you previously downloaded from this server.
You cannot download anything from the upload directory.
Remember, some ftp programs measure speed in bytes per second.
DSL speeds are measured in bits per second. There are 8 bits in a byte.
If you can download at 64 kilobytes per second then that is the same as
512 kilobits per second.
220 65.40.220.20 FTP server ready
User (65.40.220.20:(none)):
331 Anonymous login ok, send your complete email address as your password.
230-
This server is provided as a EMBARQ Speedtest server for DSL customers only.
Any other use is prohibited.
You may login using anonymous ftp and download the test files to determine your speed.
You may upload the same files to the upload directory to test your upload speed.
You may only upload the files that you previously downloaded from this server.
You cannot download anything from the upload directory.
Remember, some ftp programs measure speed in bytes per second.
DSL speeds are measured in bits per second. There are 8 bits in a byte.
If you can download at 64 kilobytes per second then that is the same as
512 kilobits per second.
230 Anonymous access granted, restrictions apply.
ftp> hash
Hash mark printing On ftp: (2048 bytes/hash mark) .
ftp> get test.1meg
200 PORT command successful
150 Opening ASCII mode data connection for test.1meg (1048576 bytes)
#
#
#
ftp: 1048576 bytes received in 5.96Seconds 175.94Kbytes/sec.
ftp>
ftp> cd upload
250 CWD command successful
ftp> put test.1meg
200 PORT command successful
150 Opening ASCII mode data connection for test.1meg
#
#
#
226 Transfer complete.
ftp: 1048576 bytes sent in 5.98Seconds 175.23Kbytes/sec.
ftp>
ftp>
I think that you might be able to redirect the output of your command to a file. e.g, at the end of the command add (assuming that you have a directory c:\temp)
your command here > c:\temp\TestOutput.text
Then in your program, add a file system watcher to watch that file and load it into the textbox when it changes. If you're doing this lots of time then you might have to dynamically generate a filename and delete the files when no-longer needed.

Multiple OS-COMMAND calls from procedure are conflicting

I have a procedure which is writing a file, emailing it using mail_files, and then an OS-DELETE statement to delete the file after it is sent. The call to the external procedure which calls mail_files or the actual OS-COMMAND itself are asynchronous. The OS is AIX 6 and the version of Progress is 102B. Here's an example below:
Here is the main procedure:
DEFINE STREAM outStr.
OUTPUT STREAM outStr TO foo.txt.
FOR EACH customer NO-LOCK:
EXPORT STREAM outStr customer.
END.
OUTPUT STREAM outStr CLOSE. /*EDIT: The problem occurs even if it's closed*/
RUN sendmail.p.
OS-DELETE foo.txt.
Here is sendmail.p:
DEFINE STREAM stMail.
OUTPUT STREAM stMail THROUGH
"mail_files -f foo#bar.com -t me#here.com -s\"subject\" -b~\foo.txt\").
PUT STREAM stMail "Email body".
OUTPUT STREAM stMail CLOSE.
In testing it on my own, I can't replicate the error. Is Progress trying to "optimize" something here? Is there anything to cleanly make it do what I want without hard-coding a pause?
EDIT:
The stream is being closed before the email attempt, but the error still occurs. No partial file is sent.
The error I get is from mail_files because it can't find the file. I've checked, and no other processes are scheduled to run which would access the file.
No such file or directory
/usr/local/bin/mail_files[268]: foo.txt: cannot open
DEFINE STREAM outStr.
OUTPUT STREAM outStr TO foo.txt.
FOR EACH customer NO-LOCK:
EXPORT STREAM outStr customer.
END.
/* Dont forget to close */
OUTPUT STREAM outStr CLOSE.
RUN sendmail.p.
OS-DELETE foo.txt.
This looks like a pathing issue to me.
In your output stream statement you never define the path that the file will be written to. This will result in the path being the current working directory of whatever application this is running under. The path of the current working directory may not necessarily be the same path that mail__files is reading from (which appears to be /usr/local/bin).
I would suggest updating your code as follows:
OUTPUT STREAM outStr TO /usr/tmp/foo.txt.
and
OUTPUT STREAM stMail THROUGH
"mail_files -f foo#bar.com -t me#here.com -s\"subject\" -b\"/usr/tmp/foo.txt\").
...or you could just try updating this line to point at /usr/local/bin (although /usr/local/bin doesn't really strike me as an appropriate directory for temporary files):
OUTPUT STREAM outStr TO /usr/local/bin/foo.txt.
If I understood correctly, Progress removes your file before mail_files use it.
If this is that, you can use unique files and cron, delete all files that are supperior to a certain date.
For example:
DEFINE VARIABLE wlc-Identifiant AS CHARACTER NO-UNDO.
DEFINE VARIABLE wlc-file-txt AS CHARACTER NO-UNDO.
wlc-Identifiant = STRING(YEAR(TODAY), "9999") + STRING(MONTH(TODAY), "99") + STRING(DAY(TODAY), "99") + REPLACE(STRING(TIME, "HH:MM:SS"), ":", "").
wlc-file-txt = wlc-Identifiant + "foo.txt".
DEFINE STREAM outStr.
OUTPUT STREAM outStr TO VALUE (wlc-file-txt).
FOR EACH customer NO-LOCK:
EXPORT STREAM outStr customer.
END.
OUTPUT STREAM outStr CLOSE.
RUN sendmail.p (INPUT wlc-file-txt). /* add the file in parameter */
/*OS-DELETE foo.txt.*/ /* It 's a cron job */
In sendmail.p:
DEFINE INPUT PARAMETER wlpic-file-txt AS CHARACTER NO-UNDO.
DEFINE STREAM stMail.
OUTPUT STREAM stMail THROUGH
"mail_files -f foo#bar.com -t me#here.com -s\"subject\" -b~\" + wlpic-file-txt + "\").
PUT STREAM stMail "Email body".
OUTPUT STREAM stMail CLOSE.
And with cron, delete old files that were created there today - 1 (it's an examle)
I hope it will help you. :)

Why "Process" class in vb.net doesn't capture errors from cmd.exe?

I'm trying to run dos commands within vb.net program and capture output. I have the following code:
Dim CMDServer As Diagnostics.ProcessStartInfo
Dim CMDReply As Diagnostics.Process
CMDServer = New Diagnostics.ProcessStartInfo
CMDServer.FileName = "cmd.exe"
CMDServer.UseShellExecute = False
CMDServer.RedirectStandardOutput = True
CMDServer.CreateNoWindow = True
CMDServer.Arguments = "/C " + command
CMDReply = Process.Start(CMDServer)
Dim Reply As String = CMDReply.StandardOutput.ReadToEnd()
The code runs successfully if command is a valid dos command, and I get the output in Reply. If the command have no output ( eg: cd\ ) Reply is null. The problem is Reply is null even when the command is invalid. How to capture errors like "command is not recognized as an internal or external command...", "The system cannot find the path specified.." etc.. Please help me. Thanks..
Error messages come in a different output stream called StandardError. Just use a StreamReader or read it directly. Of course, the RedirectStandardError-Property of your ProcessStartInfo instance must be set to True.
Also, there is a ExitCode-Property which returns the ExitCode of the program after it has finished. 0 means 'successful'. Other error codes can be found in the MSDN Documentation. Here is a list of the common exit codes. For example, 2 means The system cannot find the file specified..
Errors are probably output on CMDReply.StandardError, not CMDReply.StandardOutput; try reading it, too. (And set CMDServer.RedirectStandardError to True as well.)

get return code from plink?

In a DOS batch script, I'm running a single command on a remote (also windows) computer using plink. Formerly, this command was only run on the local machine, and was relying on the return code to determine success. Is there a way to easily get this information back through plink?
That's not possible with plink. The current consensus is to have the remote script echo its exit code to a log file, then use pscp to transfer the log file to the local machine.
See http://fixunix.com/ssh/74235-errorlevel-capturing-plink.html.
with plink 0.66
C:\Code>echo Y | "C:\Program Files (x86)\PuTTY\plink.exe" bob#myserver exit 42
C:\Code>echo %ERRORLEVEL%
42
Also for #John Wiersba's concern about when a connection cannot be made, this appears to be fixed
C:\CodeMisc>echo Y | "C:\Program Files (x86)\PuTTY\plink.exe" bob#garbageservername exit 42
Unable to open connection:
Host does not exist
C:\Code>echo %ERRORLEVEL%
1
Also note the piping of echo Y ... this enables you to accept the server fingerprint automatically (a little dangerous to say the least ... but our login server is load balanced, so you are always getting different fingerprints :( )
However as #LeonBloy notes, plink still has some connection conditions which return a zero exit code. If you know your exit code range and you don't have a good way of communicating back to windows via a file. You could either +3 to the exit code (if you know the exit code will never == 253-255) or you could apply a bitwise OR (I'd suggest exit $(($?|128)) - in bash).
Or if you don't care about the exact exit code, you could return 2 for success, and zero for failure. Thus a non-two exit code would indicate failure. In bash this would be: echo $((($?==0) << 1)). This would be by far the most robust general purpose solution, but you should make sure your exit code is logged for debug-ability.