Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix to PC data issue

Status
Not open for further replies.

lleemon

Programmer
Mar 26, 2002
21
GB
I am working on a project that required data to be pulled from a hp-unix box and populate a excel worksheet. One option they are wanting to include in this app is to let a user select the unix directory to look at files. Do far my solution is to use the inet control to get the list of files/directories and put into a text file then display on screen by reading text files. My issue is when I do a DIR I get funky character/letter at the front and end of the output. I can not just change the vbLF with vbCrLf. This is not the solution.

Does know how to get just the info without the unix crap?
Thanks in advance.

Here is my code to pull the list:
Public Sub sbGetDirList()
'=========================================================
'=========================================================
Dim sPathFile As String

Inet1.URL = "ftp://IP_OF_UNIX_BOX"
Inet1.UserName = username
Inet1.Password = password
Inet1.Protocol = icFTP
Inet1.Execute Inet1.URL, "cd /log/dir/
Do While Inet1.StillExecuting
DoEvents
Loop

Inet1.Execute Inet1.URL, "DIR *.txt "
Do While Inet1.StillExecuting
DoEvents
Loop
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
'=========================================================
'=========================================================
Dim vtData As Variant ' Data variable.
Dim sPath As String

Select Case State
' ... Other cases not shown.
Case icResponseCompleted ' 12
' Open a file to write to.
sPath = gsDir & "alltxtfiles.txt"

Open sPath For Binary Access Write As #1

' Get the first chunk. NOTE: specify a Byte
' array (icByteArray) to retrieve a binary file.
vtData = Inet1.GetChunk(1024, icString)

Do While LenB(vtData) > 0
Put #1, , vtData
' Get next chunk.
vtData = Inet1.GetChunk(1024, icString)
Loop
Put #1, , vtData
Close #1
End Select
End Sub
 
Might I ask what the "funky character/letter" is?
Also, What flavor of UNIX? I used to work with SCO UNIX and a bit of LINUX.
Never tried to do what you are doing and have no way to check my guess, so either thank me or call me an idiot depending on the results, but I think "DIR *.txt "
should read "l *.txt in SCO UNIX or "ls *.txt" in LINUX.
Remember to lose the quotes. Terry (cyberbiker)
 
Terry - the funky characters/letter not the same each directory accessed. An example is in notepage the first character is a black square, space, character T, and space then the first item in the list. I have set up a loop and am finding the characters to be ascii characters less then 31 or greater then 128. I can just replace any of these characters with NULL but don't know if a legitimate character shows up or not.

Unix flavor = HP-Unix

As for the DIR *.txt
In the MSDN Library Visual Studio 6.0 documents they say to do the following for Using the Internet Transfer Control:

....
DIR [ file1 ]
Searches the directory specified in file1. If file1 isn't supplied, the current working directory is searched. Use the GetChunk method to return the data.
Example: Execute , "DIR /mydocs"
.....

 
Ok. I do not know if I am up to the explaination since it has been some yime since I worked with UNIX now,. Perhaps you should check the UNIX forum, but here goes:
In SCO UNIX (from what I know HP-UNIX uses the same) the l command lists everything in that directory. (Dir is DOS, not UNIX). Since you are searching the UNIX directories, I would think you you would need the UNIX command, not the DOS command.
Let me know Terry (cyberbiker)
 
Actually, "dir" shouldn't cause any problems, as it's a valid FTP command, and it's the FTP server that's responding to it, not the OS shell. Usually, "dir" and "ls" do pretty much the same thing anyway. At any rate, I wouldn't pay too much attention to what the Controls Reference says regarding FTP commands. The FTP server's documentation would be a more reliable source of information.

Have you tried running other commands and checking the output for those funky characters? Also, is the number of funky characters you're getting fixed? I'm wondering if maybe they're some kind of acknowledgement from the server or something.
I'm also curious as to exactly why you can't just strip those characters out. If they're not between ASCII 32 and 127, and are only at the beginning and end of input, the chances of them containing any legitimate file information seems rather small.
 
Good point Hacker. I only did ftp with LINIX once and that was 3 years ago.
The basic point is that UNIX handles things differently than dos (CR and LF come to mind first) When the file transfer occurs are you bringing a dos format file or a UNIX format file? (am I making sense?)
There are utilities in UNIX (doscp and utod) to change UNIX text files to Dos text files.
Also, I would open the text files in the older versions of Norton Editor if that is available or with dosedit (assuming that is still hiding under windows somewhere).
I never had good results with notepad and word when trying to edit text files created on a UNIX system, I always used NE, but have seen people use dosedit.
I do not have anyway to check this at this time, but I think, you will find that the character you are actually getting is the ^.
It should be safe to remove this as hacker indicated.
Terry (cyberbiker)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top