• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1010
  • Last Modified:

FTP files from Unix box

I need to get 40 files from Unix box with *.cfg format using Inet. Please provide sample code. Thanks
0
dhamijap
Asked:
dhamijap
  • 29
  • 22
  • 4
  • +1
1 Solution
 
Richie_SimonettiIT OperationsCommented:
Why don't use FTP?
0
 
dhamijapAuthor Commented:
Richie Simonetti:
Yes, I do have FTP running on Unix box. I am using inet on windows to ftp the files. If you are talking something else please tell me how?
0
 
Richie_SimonettiIT OperationsCommented:
Yes, using FTP commands rather than Inet control.
Sorry for didn't be more specific before.
Actually, i have a dll active x that wraps almost all the funcionallity of Wininet.dll, are you interesdted in it?
(Is free ;)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
dhamijapAuthor Commented:
Why not I am open to all ideas.
0
 
Richie_SimonettiIT OperationsCommented:
Wait.
I will post it somewhere on internet and give you the URL.
0
 
Richie_SimonettiIT OperationsCommented:
The site is unable to post binary files, what do you want to do?
0
 
dhamijapAuthor Commented:
email me at dhamijap@yahoo.com
0
 
glass_cookieCommented:
Hi!

Here's a file over the net, but I'm not sure if it's applicable or not:

Download...
http://www.vb-helper.com/Howto/ftp.zip

Description: Upload and download files using FTP (4K)

That's it!

glass cookie : )
0
 
Richie_SimonettiIT OperationsCommented:
Well, it is too late to send you by mail since dll is at work and i don't go back to monday.
But...
http://www.freevbcode.com/ShowCode.Asp?ID=1991
http://www.freevbcode.com/ShowCode.Asp?ID=1593
http://www.freevbcode.com/ShowCode.Asp?ID=731

And there is another posibility without using any dll or wininet if i can find the code on my populated hard disk.
0
 
Richie_SimonettiIT OperationsCommented:
0
 
dhamijapAuthor Commented:
Richie and glass_cookie:

I visited the sites but I donot know where to begin. Please provide sample code as I requested.

How do I get 40 files *.cft from a unix box FTP site?
Thanks
0
 
Richie_SimonettiIT OperationsCommented:
Well, would you like to email you the FTPWrapper?
If so, give me an email address.
Cheers
0
 
dhamijapAuthor Commented:
Richie:
Please email me at dhamijap@yahoo.com
0
 
Richie_SimonettiIT OperationsCommented:
I just sent it.
By the way, if someone else is interested in it...
0
 
dhamijapAuthor Commented:
Richie Simonetti:
Can we start on this FTP business?
0
 
Richie_SimonettiIT OperationsCommented:
As you wish!
0
 
dhamijapAuthor Commented:
So let us discuss what I need get done and agree on something to do. From a windows box in VB code I need to get the names of file and their properties like name, date created, size etc. The I do some checking and decide which files I need and i put them in an array. Then i want to loop through and get them from a unix box. Please help me to decide how to do it.  
0
 
Richie_SimonettiIT OperationsCommented:
Well., that is not primitive question but....
We will use FTPWrapper class?
0
 
dhamijapAuthor Commented:
would this give me lot of control?
Is FTPWrapper class native to VB?
0
 
Richie_SimonettiIT OperationsCommented:
It was wrote with vb6 sp5.
Let me do something tonight (here is 6.32 pm) and i will come back tomorrow with a working code.(I hope;)
Cheers
0
 
Richie_SimonettiIT OperationsCommented:
Hi, good mourning! (here :)
take a look at this:


You must take care of, at least, one matter:
Not all ftp servers returns file sizes.
With this in mind, let's do some work....

The steps required are:
1). Create a FTP session
2). Log onto server
3). (Optional) Navigate to a specific dir
4). Retrieve a list of files with properties
5). Do whatever what we want with those files
6). Logout and close session


Steps:
Before continue any longer, set a reference in your project to FTPWrapper class mentioned
earlier.
We need to create some types, vars, controls and a function.
Add tree labels(label1), textboxes(text1) and tree command buttons(cmd) in arrays.
Add one more label(label2) and a listview(lstView).

NOTE: FTPWrapper has a function incorporated to return an array of files found.
      Since we need other properties of files, we must to create a new one and
      not use what is provided with the class :(

This is a complete form with all the stuff:
'------- Begin form code

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "Mscomctl.ocx"
Begin VB.Form frmEnumFiles
   Caption         =   "Form1"
   ClientHeight    =   4410
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6855
   LinkTopic       =   "Form1"
   ScaleHeight     =   4410
   ScaleWidth      =   6855
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmd
      Caption         =   "&Get Files"
      Height          =   390
      Index           =   2
      Left            =   5490
      TabIndex        =   10
      Top             =   960
      Width           =   1215
   End
   Begin VB.CommandButton cmd
      Caption         =   "Log &Off"
      Height          =   390
      Index           =   1
      Left            =   5490
      TabIndex        =   9
      Top             =   510
      Width           =   1215
   End
   Begin VB.CommandButton cmd
      Caption         =   "&Log on"
      Height          =   390
      Index           =   0
      Left            =   5475
      TabIndex        =   8
      Top             =   60
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   315
      IMEMode         =   3  'DISABLE
      Index           =   2
      Left            =   1020
      PasswordChar    =   "*"
      TabIndex        =   5
      Top             =   945
      Width           =   3165
   End
   Begin VB.TextBox Text1
      Height          =   315
      Index           =   1
      Left            =   1020
      TabIndex        =   3
      Top             =   585
      Width           =   3165
   End
   Begin VB.TextBox Text1
      Height          =   315
      Index           =   0
      Left            =   1020
      TabIndex        =   1
      Top             =   60
      Width           =   3165
   End
   Begin MSComctlLib.ListView lstView
      Height          =   2355
      Left            =   90
      TabIndex        =   7
      Top             =   1575
      Width           =   6645
      _ExtentX        =   11721
      _ExtentY        =   4154
      View            =   3
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   3
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
         Key             =   "Name"
         Text            =   "Name"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
         SubItemIndex    =   1
         Key             =   "DateCreated"
         Text            =   "Date Created"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628}
         SubItemIndex    =   2
         Key             =   "Size"
         Text            =   "Size"
         Object.Width           =   2540
      EndProperty
   End
   Begin VB.Label Label1
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      BackStyle       =   0  'Transparent
      Caption         =   "List of files on:"
      ForeColor       =   &H80000008&
      Height          =   195
      Index           =   3
      Left            =   90
      TabIndex        =   6
      Top             =   1365
      Width           =   1005
   End
   Begin VB.Label Label1
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      BackStyle       =   0  'Transparent
      Caption         =   "Password"
      ForeColor       =   &H80000008&
      Height          =   195
      Index           =   2
      Left            =   90
      TabIndex        =   4
      Top             =   1005
      Width           =   690
   End
   Begin VB.Label Label1
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      BackStyle       =   0  'Transparent
      Caption         =   "User ID:"
      ForeColor       =   &H80000008&
      Height          =   195
      Index           =   1
      Left            =   90
      TabIndex        =   2
      Top             =   645
      Width           =   585
   End
   Begin VB.Label Label1
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      BackStyle       =   0  'Transparent
      Caption         =   "FTP Server"
      ForeColor       =   &H80000008&
      Height          =   195
      Index           =   0
      Left            =   90
      TabIndex        =   0
      Top             =   120
      Width           =   810
   End
End
Attribute VB_Name = "frmEnumFiles"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Constantes:
Private Const MAX_PATH = 260
'************

' Tipos:
Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
End Type
Dim ft As CFTP
Dim arrFileRemote() As String
Private Function EnumFilesFTP(ByRef intFilesFound As Integer, Optional sExtension As String = "*.*", Optional lv As ListView = Nothing) As String()

Dim arrFiles() As String, idx As Long
Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
   
'create a buffer
pData.cFileName = String(MAX_PATH, 0)
   
'find the first file
hFind = FtpFindFirstFile(ft.FTPID, sExtension, pData, 0, 0)
   
'if there's no file, then exit sub
If hFind = 0 Then Exit Function

'show the filename
Dim FName As String
FName = Left$(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
If FName <> "." Then
   idx = idx + 1
   ReDim arrFiles(idx)
   arrFiles(idx) = FName
   If Not lv Is Nothing Then
    lv.ListItems.Add idx, , FName
    lv.ListItems(idx).ListSubItems.Add 1, , pData.ftCreationTime
    lv.ListItems(idx).ListSubItems.Add 2, , Format$(CStr(pData.nFileSizeLow / 1024), "0,00") & "Kb"
   End If
End If

Do
    'create a buffer
    pData.cFileName = String(MAX_PATH, 0)
    'find the next file
    lRet = InternetFindNextFile(hFind, pData)
    'if there's no next file, exit do
    If lRet = 0 Then Exit Do
    'show the filename
    FName = Left$(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    If FName <> ".." Then
       idx = idx + 1
       ReDim Preserve arrFiles(idx)
       arrFiles(idx) = FName
       If Not lv Is Nothing Then
        lv.ListItems.Add idx, , FName
        lv.ListItems(idx).ListSubItems.Add 1, , pData.ftCreationTime
        lv.ListItems(idx).ListSubItems.Add 2, , Format$(CStr(pData.nFileSizeLow / 1024), "0,00") & "Kb"
       End If
    End If
Loop
   
'close the search handle
InternetCloseHandle hFind
'returns names of files found and quantity
intFilesFound = idx
EnumFilesFTP = arrFiles
End Function


Private Sub cmd_Click(Index As Integer)
Select Case Index
Case 0
    ft.FTPOpenSession ACCESSDIRECT
    If Not (ft.FTPConnect(Text1(0).Text, Text1(1).Text, Text1(2).Text, sFTP, 21) <> False) Then
        MsgBox "An error has ocurred while trying to connect to FTP Server.", vbCritical, App.EXEName
        cmd(2).Enabled = False
    Else
        cmd(2).Enabled = True
    End If
Case 1
    ft.FTPCloseSession
Case 2
    Dim lCount As Integer
    arrFileRemote = EnumFilesFTP(lCount, "*.*", lstView)
End Select

End Sub

Private Sub Form_Load()
Set ft = New CFTP
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set ft = nothing
End Sub
0
 
dhamijapAuthor Commented:
I found cFtpWpp 1.0 type library
is this the one?
0
 
dhamijapAuthor Commented:
I found cFtpWpp 1.0 type library
is this the one?
0
 
dhamijapAuthor Commented:
I found cFtpWpp 1.0 type library
is this the one?
0
 
Richie_SimonettiIT OperationsCommented:
I didn't sent it to you by email a time ago?
0
 
dhamijapAuthor Commented:
yes you did let me find it an put it on. when i do i will acknowledge
0
 
Richie_SimonettiIT OperationsCommented:
OK.
Just put in your wndows\system folder and registre it.
You can add to your project from project, references menu.
If it is not listed, do a search with examine button to locate it.
Cheers
0
 
dhamijapAuthor Commented:
I registered and referenced it.
when i run it, it gives me erro on this line:

ft.FTPOpenSession ACCESSDIRECT

data memeber not found
0
 
Richie_SimonettiIT OperationsCommented:
Do you get autolist when you write dot after ft?
0
 
Richie_SimonettiIT OperationsCommented:
Anyway, it was tested with several kinds of connections (Dial-up, proxy and peer-to-peer) without any problem.
0
 
Richie_SimonettiIT OperationsCommented:
da,da,da! what a stupid person i am!
You have an old dll, sorry.
I will e-mail you in a moment.
I apologize again.
;)
0
 
Richie_SimonettiIT OperationsCommented:
Maybe you must do a little change to code posted when reference that new version.
I beg you that unregister previous one and delete it.
0
 
dhamijapAuthor Commented:
ok I got your new FTPwarper. How do I remove the old FTPwrapter. Do you want me to find the files and delete them. How do i unregister then?
0
 
Richie_SimonettiIT OperationsCommented:
Go to start/run and type
regsvr32 /u c:\windows\system\nameofdll.dll
and hit enter.
Then delete the file and copy new one and registre it with

regsvr32 c:\windows\system\cFTPWrapper.dll
0
 
dhamijapAuthor Commented:
Sorry.
I had to do something else.
I undeleted and re-registered again.
Let us continue
0
 
Richie_SimonettiIT OperationsCommented:
OK. I don't know where we are!
0
 
dhamijapAuthor Commented:
I have created a project added the code you gave me. Registered the DLLs. when i run it nothing happens. I did F8 it only processes
Private Sub cmd_Click(Index As Integer)
and selects case 0
and enables logon button.
0
 
Richie_SimonettiIT OperationsCommented:
First of all, we need to know if we are assing valid values to ftpopensession and ftpconnect.
0
 
Richie_SimonettiIT OperationsCommented:
Example:
Select Case Index
Case 0
    ft.FTPOpenSession ACCESSDIRECT
    If Not (ft.FTPConnect("128.0.0.1", "myself","mypassword", sFTP, 21) <> False) Then
        MsgBox "An error has ocurred while trying to connect to FTP Server.", vbCritical, App.EXEName
        cmd(2).Enabled = False
    Else
        cmd(2).Enabled = True
    End If
Case 1
    ft.FTPCloseSession
    cmd(2).Enabled = False
Case 2
    Dim lCount As Integer
    arrFileRemote = ft.EnumFilesFTP(lCount, "*.*")
   
    Dim idx As Integer
    lstView.ListItems.Clear
    For idx = 1 To lCount
        lstView.ListItems.Add idx, , arrFileRemote(idx)
    Next idx
End Select
0
 
dhamijapAuthor Commented:
the code in your expmple is like this:   (Do you want me to replace it with the one you sent now?)

Private Sub cmd_Click(Index As Integer)
Select Case Index
Case 0

   ft.FTPOpenSession ACCESSDIRECT
   If Not (ft.FTPConnect(Text1(0).Text, Text1(1).Text, Text1(2).Text, sFTP, 21) <> False) Then
       MsgBox "An error has ocurred while trying to connect to FTP Server.", vbCritical, App.EXEName
       cmd(2).Enabled = False
   Else
       cmd(2).Enabled = True
   End If
Case 1
   ft.FTPCloseSession
Case 2
   Dim lCount As Integer
   arrFileRemote = EnumFilesFTP(lCount, "*.*", lstView)
End Select

End Sub
0
 
Richie_SimonettiIT OperationsCommented:
Well, no, just as an example.
When you push getfiles button, what happens?
I did a try with that dll on the following situations with full success:
1) By proxyserver
2) By dial-up connection
3) Direct to a ftp server throghout the LAN.

And, we are using it right now to transfer/delete files and creates/deletes directorios on a FTP remote site.
0
 
dhamijapAuthor Commented:
If i go to command prompt and do this:
ftp labhost
user: xxxx
pwd: xxxx
cd .. enter
ls
IGET:
filename.xxx
filename.XXX

to your question.
when I enter labhost + uid + pwd and hit enter on the form nothing happens it just stands still.
I have created a new project referenced to your dlls and inserted the longe code you gave me on 08/23/2001 06:50AM PST.
Now Please tell me what to do next!




0
 
Richie_SimonettiIT OperationsCommented:
i am checking...
Use Ip address instead name server just to try....
0
 
dhamijapAuthor Commented:
I tried but the same results.
0
 
Richie_SimonettiIT OperationsCommented:
Well, don't desperate. I know that this dll works.
questions:
1) How do you connect to internet,proxy, dial-up, adsl?
I am asking this because dll is strong related to those issues.
Example: If you use a proxy to connect to internet, this dll tries to search your unix server at internet(!)
If you have configured your browser to automatic dial up to internet, ftpConnect tries to use that to connect to your Unix server.
I will pass you how is my own config regarding IE.
wait...
0
 
Richie_SimonettiIT OperationsCommented:
Hi, long time non see you. We could continue on this. I am sure that code works since i use it in a daily basis every ten minutes.
0
 
dhamijapAuthor Commented:
I got laid off so I do not think I can continue this.
Thanks for your help.
Pradeep
0
 
DanRollinsCommented:
dhamijap, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Accept Richie_Simonetti's comment(s) as an answer.
    *** RIP.  Richie, I am weeping in your behalf.

DanRollins -- EE database cleanup volunteer
0
 
Richie_SimonettiIT OperationsCommented:
"....
*** RIP.  Richie, I am weeping in your behalf.
....
"

Wow! why?!
0
 
DanRollinsCommented:
It looks like you spent several weeks working with this user, some of it at the tutorial level, painfully drawing one piece of information after another from him... then poof, he disapppears, discarding you like the damp kleenex that dry my eyes.

-- Dan
0
 
Richie_SimonettiIT OperationsCommented:
Yeah, it was a hard work. I don't like to let people in the rain if i could help. I already had that class (indeed, i am currently ameliorating it ;) so hard work was trying to explain the usage (which is intuitive, i think)
Thanks for your support, Dan.
(PS: It appears like i know you forever...:)
0
 
dhamijapAuthor Commented:
Hello everybody:
I WAS LAID OFF FROM the company. I no longer need this. Please stop responding.
Pradeep
0
 
DanRollinsCommented:
hi dhamijap,
Thanks for returning to finalize this question.  The EE Expert, Richie_Simonetti, spent a lot of time working to help you with this problem.  Even if you no longer need this particular answer, it would be the right thing for you reward his efforts.  So please:

1) Click the [Accept Comment as Answer] button next to one of Richie_Simonetti's comments.
2) Click the Excellent radio button.
3) Click the [Submit] button.  

Thanks!
-- Dan
 
0
 
dhamijapAuthor Commented:
Although the solution may work. Since I was laidoff from my company and I am India I am just accepting the answer. Thanks everybody who tried to help me.

PRADEEP
0
 
Richie_SimonettiIT OperationsCommented:
Amazing, "B" grade!
0
 
DanRollinsCommented:
A torrent of saltwater has shorted out my keyboard.  I simply cannot continue...
-- Dan
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 29
  • 22
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now