EONE BLOG

Tech Tuesday: Creating a Task in SmartConnect to get a file from an FTP site


This weeks Tech Tuesday is from our very own Chris Dew, our Director of Product Management, who will explain how to create a task in SmartConnect to get a file from an FTP site.

We get quite a few customers that want to take files from a FTP site and utilize this file as the source of their data when running a map inside of SmartConnect. Today I have created a sample Task script that will allow you to grab a file in a Pre Map Task and then use it for the integration.

First you can simply click on the Tasks button in any existing map, and then choose a new task called run script. This is where you can now copy the script below and paste into this window (like in the image below).



=================================================================

‘EXAMPLE OF HOW TO USE FtpWebRequest

        ‘Configuration
        Const localFile As String = “C:UsersAdministratorDownloadsftpREADME.txt”
        Const remoteFile As String = “/README.txt”
        Const host As String = “ftp://ftp.swfwmd.state.fl.us/pub/”
        Const username As String = “anonymous”
        Const password As String = “email@email.com”

        ‘Create a request
        Dim URI As String = host & remoteFile
        Dim ftp As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(URI), System.Net.FtpWebRequest)
        ‘Set the credentials
        ftp.Credentials = New System.Net.NetworkCredential(username, password)
        ‘Turn off KeepAlive (will close connection on completion)
        ftp.KeepAlive = False
        ‘we want a binary
        ftp.UseBinary = True
        ‘Define the action required (in this case, download a file)
        ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

        ‘If we were using a method that uploads data e.g. UploadFile
        ‘we would open the ftp.GetRequestStream here an send the data

        ‘Get the response to the Ftp request and the associated stream
        Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
            Using responseStream As IO.Stream = response.GetResponseStream
                ‘loop to read & write to file
                Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                    Dim buffer(2047) As Byte
                    Dim read As Integer = 0
                    Do
                        read = responseStream.Read(buffer, 0, buffer.Length)
                        fs.Write(buffer, 0, read)
                    Loop Until read = 0 ‘see Note(1)
                    responseStream.Close()
                    fs.Flush()
                    fs.Close()
                End Using
                responseStream.Close()
            End Using
            response.Close()
        End Using
return true
=================================================================

The only configuration that needs to be done is at the very top where you determine four things:
1) The name and location you want to put the file on your network
2) The name of the remote file
3) FTP Site
4) Username
5) Password

Have fun with this one and use your imagination on other scripts you can use. If you have a suggestion for a new script please let me know.

chris.dew@eonesolutions.com

Thanks,
Chris Dew

Interested in SmartConnect? Please email us at sales@eonesolutions.com and we would be happy to assist you!

1 Comment

  1. RLMcVicar on July 11, 2014 at 2:40 pm

    When can we start seeing the SmartView and SmartList Builder in a web Client in or outside of Dynamics GP?

Leave a Comment





RECENT POSTS


Register Soon! SmartConnect Bootcamp in Houston in January 2020
eOne's Greatest Hits of 2019: Tech Tuesday
SmartConnect Office Hours: Tracking Deletes in Dynamics GP
Join a Popdock Demo!
Employee Spotlight: Raymond Porter

POPULAR POSTS


2016 SmartConnect Integration Bootcamps
Tech Tues: Automatically refreshing Pivot Tables in Excel Refreshable Reports
Happy Thanksgiving from the eOne team!
New Releases of Extender and SmartList Builder
2017 SmartConnect Integration Bootcamps

CATEGORIES

ARCHIVES

open all | close all

TAGS

Business Central CRM Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News eOne Spotlight Events Excel Excel Report Builder Extender Extender Enterprise Flexicoder GP GPUG integration Meet the Team Microsoft dynamics crm Microsoft Dynamics GP Office Relationships partners Popdock release Reporting SalesForce SalesForce.com scripting SmartConnect SmartConnect.com SmartConnect Bootcamp SmartConnect Office Hours SmartList SmartList Builder SmartList Designer SmartView SQL Support Tech Tuesday Templates training Zendesk

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.